Get_adjacent_post workaround?
-
Quick question I am hoping that you can assist with or at least confirm that this will or will not work the way I am trying to use the plugin.
I have a post type with a bunch of ajax filtering – The sort order from the plugin works fine here.
When you click one of the single posts, I am making another ajax call that passes the post ID and loads in the post data in a popover with next/prev arrows to toggle between other posts.
The way I am currently handling the arrows is in the WP Query for a single post where I then use get_adjacent_post() to get the prev/next post objects.
$next_post = get_adjacent_post(true, '', false, 'category'); $previous_post = get_adjacent_post(true, '', true, 'category');
From there I build the arrows using
echo '<a href="#" data-target="'. $previous_post->ID .'" class="modal-prev'. $prev .'">'; echo '<a href="#" data-target="'. $next_post->ID .'" class="modal-next'. $next .'">';
Then in the template I use that data-target attribute to pass the next or previous ID back to the ajax function to load the next post. This is where I am a little hung up as get_adjacent_post() isn’t respecting the sort order from this plugin.
I know you mention using get_adjacent_post_link() but that isn’t going to necessarily work for me because I really just need the ID’s, not the full permalink.
Is get_adjacent_post() supposed to work with this custom sort order?
Thanks in advance.
- The topic ‘Get_adjacent_post workaround?’ is closed to new replies.