I just set up a wordpress website with 150 posts of a custom post type. On the single pages of each post, I want to have a “Previous” and “Next” to let readers read more post on my website, is the code correct, please help.
<?php $next_post = get_next_post();
if ($next_post) {
echo ‘<a rel=”next” href=”‘ . get_permalink($next_post->ID) . ‘”>Next</a>’;
} ?>
After I add the code, it is very random, the post may jump to post #15 or post#56, it can not be listed by sequence. In fact, I prefer to go through the posts in alphabetical order of their slug. Ignoring taxonomy.
I have modified the code for you, could you please try this, you need to replace the post type.
I managed to correct your code to this new one, The limit of 5 posts was fixed with ‘posts_per_page’ => -1. The rest seems too complex for what is actually needed.