0

From this answer, I now have an adjusted WP_Query statement (I added the $paged variable):

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array( 'post_type' => 'laptop', 'postsperpage' => '30', 'max_num_pages' => 20, 'paged' => $paged) );

if ( $loop->have_posts() ) { ?>
   ...output content....
} ?>

<?php if ( $loop->max_num_pages > 1 ) : ?>
<div id="nav-below" class="navigation">
  <div class="nav-previous">
    <?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Previous', 'domain' ) ); ?>
  </div>
  <div class="nav-next">
    <?php previous_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'domain' ) ); ?>
  </div>
</div>
<?php endif; }
   wp_reset_postdata();
?>

Nothing is output in <div class="nav-previous"> or <div class="nav-next">.

Can you see what is wrong here please?

2

From WordPress Codex:

Add the $max_pages parameter to the next_posts_link() function when querying the loop with WP_Query. To get the total amount of pages you can use the 'max_num_pages' property of the custom WP_Query object.

So:

next_posts_link( __( 'Next <span class="meta-nav">&rarr;</span>', 'domain' ), $loop->max_num_pages );
  • Thanks. After making the change above, I only receive a ← Previous link, pointing to page 2, and no Next link... – Steve Mar 11 '17 at 7:14
  • 1
    Because you have put the word previous inside next_posts_link – Laxmana Mar 11 '17 at 13:27

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.