- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi guys,
got a quite frustrating issue!
I have post navigation to go to the next/prev post on the single of a custom post type. It works perfectly for all posts EXCEPT the very first and the very last item.
On these pages there should only be a next OR a prev post, but in my case get_previous_post and get_next_post are returning the same post.
Here’s my code:
$prevPost = get_previous_post();
$nextPost = get_next_post();
if ($prevPost) {
echo previous_post_link(‘%link‘);
}
if ($nextPost){
echo next_post_link(‘%link‘);
}
Any ideas?
I have this same problem on the archive pages of my own site. Looking forward to what some smarter people have to say on the subject!
Straight from http://codex.wordpress.org/Function_Reference/get_next_post.
$next_post = get_next_post();
if (!empty( $next_post )): ?>
ID ); ?>”>post_title; ?>
Or, I am I missing something?
Thanks, I did see that in the Codex but unfortunately get_next_post() is returning a post even when there is no ‘next’ post (and likewise for get_previous_post()), rather than null as per the docs.
I came across the Ambrosite Next/Previous Post Link Plus http://wordpress.org/extend/plugins/ambrosite-nextprevious-post-link-plus/, which has solved my problem :)
Cheers