There are three ways I would suggest pagination with a custom wp_query message. Unfortunately, to this day there is not much good information about this, or at least in some cases this is unclear. Hope this helps!
Please note: you also have wp_reset_postdata () in the wrong place, but you need even more to get it working correctly.
Option 1 - use the variable max_num_pages
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 1, 'paged' => $paged, 'post_type' => 'cpt_type' ); $cpt_query = new WP_Query($args); ?> <?php if ($cpt_query->have_posts()) : while ($cpt_query->have_posts()) : $cpt_query->the_post(); ?> //Loop Code Here... <?php endwhile; endif; ?> <nav> <ul> <li><?php previous_posts_link( '« PREV', $cpt_query->max_num_pages) ?></li> <li><?php next_posts_link( 'NEXT »', $cpt_query->max_num_pages) ?></li> </ul> </nav>
You will see above, a slightly different format for previous_posts_link and next_posts_link , which now access the variable max_num_pages . Be sure to use your own query variable name when accessing max_num_pages . Notice that I'm using $ cpt_query, as this is a variable for my query.
Option 2 - temporarily use the $ wp_query variable for your loop request
This is what many recommend, but be careful to assign the $ wp_query variable to the temp variable and reassign it, or you will run into all the trouble. That's why I recommend option number 1. As noted in CSS Tricks , you can do something like this:
<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=6&post_type=news'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php endwhile; ?> <nav> <?php previous_posts_link('« Newer') ?> <?php next_posts_link('Older »') ?> </nav> <?php $wp_query = null; $wp_query = $temp;
Option 3 - use the WP-pagenavi plugin
As another option, you can use the WP-pagenavi plugin and configure your request, as in Option No. 1. But make one change to the code, delete everything inside the element and replace it with this function as soon as you install the plugin. So you are done:
<nav> <?php wp_pagenavi( array( 'query' => $cpt_query ) ); ?> </nav>