• I’m displaying the content of a few pages (not posts!) on a page using WP_Query; I have limited the amount of items to display and now I’m wondering how to add “next” and “prev” links to it. What I have isn’t working:

    $query = new WP_Query(array(
    	'post_type' => 'page',
    	'posts_per_page' => 2,
    	'paged' => get_query_var('page')
    ));
    if($query -> have_posts()):
    	while($query->have_posts()) : $query->the_post();
    ?>
    // stuff here
    	<?php next_posts_link(); ?>
    	<?php previous_posts_link(); ?>
    	<?php
    		endwhile;
    		wp_reset_postdata();
    	endif;
    ?>

    What am I doing wrong? (P. S.: I do have more than two pages)

Viewing 1 replies (of 1 total)
  • I believe that next and previous_posts_links() only work with $wp_query. Try saving the current query and using query_posts() instead of new WP_Query().

Viewing 1 replies (of 1 total)
  • The topic ‘WP_Query and prev/next links’ is closed to new replies.