1

I'm using get_next_post_link() and get_previous_post_link() within the loop but the returned posts are not correct.

get_next_post_link() shows the previous post and get_previous_post_link() gives the current post. Below the context of these links:

$args['name'] = $postname;
$query = new WP_Query($args);

if($query->have_posts())
    {
    while ($query->have_posts())
        {
        $query->the_post();

        $id         = get_the_ID();
        $title          = get_the_title();
        $content        = get_the_content();

        $nextpost       = get_next_post_link('Next: %link');
        $previouspost   = get_previous_post_link('Prev: %link');
        }
    }
0

This has been solved by changing Site Address (URL) in Settings > General to the path that matches with the posts's path. I was pulling in posts from another location in my website that did not match with the original (default) path of the post.

| improve this answer | |
  • This is an interesting issue. Did you know that your rest URL also changes with weird things and just rest_url isn't enough? – coolpasta May 1 '19 at 23:11
0
get_next_post_link();
get_previous_post_link();

These work on single posts for navigation from one single post to another NOT pagination for archive pages unless you use get_query_var( 'paged' )

| improve this answer | |
-1

I think you can not pass proper argument. Please check this link for reference : https://codex.wordpress.org/Function_Reference/get_next_posts_link

| improve this answer | |
  • You refer to the next archive page post link. The get_next_post_link should be singular to get the adjacent post – Warface May 1 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.