This could be my bug, but I’m confused about what’s happening.
I have a client using my GT Vouchers plugin and in one of the widgets, I show the most recent vouchers and link to them. On his site, the links come back NULL when I call get_post_permalink( $voucher_post->ID );
I traced this and get_post_permalink runs your filter geodir_listing_permalink_structure and this is where the NULL comes from. My link is passed in, the post information is there etc. The code I don’t quite get is this (line 1028) but I cleaned it up to post here:
if ( isset( $post_obj->ID ) && isset( $post->ID ) && $post_obj->ID == $post->ID ) {
} elseif ( isset( $post_obj->post_status ) && $post_obj->post_status == 'auto-draft' ) {
return $post_link;
} else {
$orig_post = $post;
$post = $post_obj;
}
I’ve debugged this and we’re hitting the third condition – the ELSE. My $post_obj coming in has an ID of 321, but the current post – for some reason – is 128, the don’t match and so the posts get swapped. Which is fine, but confusing.
Then we get to 1054:
if ( isset( $gd_permalink_cache[ $post->ID ] ) && $gd_permalink_cache[ $post->ID ] ) {
if ( isset( $orig_post ) ) {
$post = $orig_post;
}
return $gd_permalink_cache[ $post->ID ];
}
The code checks if the cache exists for $post->ID (which is 321 coming from my $post_obj) and if it is set checks if we have an $orig_post and then returns THAT link instead, which is obviously not going to be the link that I asked for.
Any thoughts on WHY this is and how I should handle this? Maybe because I am in a widget and don’t setup the full global $post object? but I’m not sure why GeoDirectory is overriding that…