Next Post doesn't always link to correct post & if last post
-
I have a website with custom post types, this specific post type I am working with is “News”. I have a list of News posts which are displaying as they should, (in descending order of their publish date). However, for some reason I can’t get the get_next_post() function to work correctly. It’s actually working for 90% of the posts, however the newest two posts it seems to be completely skipping. I will be on post 1 and it links next post to post 3 instead of post 2.
This is how I am displaying my list of posts:
$args = array("post_type" => "news", 'posts_per_page' => 5, "paged" => $paged, "orderby" => "date", "order" => "DESC"); $wp_query = new WP_Query($args);
My single post pages is single-news.php. It’s not in a loop or anything, it just uses the $post variable to get all of the information for the posts.
I am using
get_permalink(get_next_post()->ID)
to get the permalink, however like i stated above it’s not always correct.I hope that’s enough information for that issue, but alongside this I would also like to be able to detect on the single post page if it’s the last post in the News post type so I can remove the Next Post button.
Thanks!
- The topic ‘Next Post doesn't always link to correct post & if last post’ is closed to new replies.