I have a custom post type with it's own archive page. I'm running a custom loop, displaying 1 result. I'm trying to paginate these results, but I'm having some strange issues that I can't seem to figure out.
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'news-events', 'posts_per_page' => 1, 'order' => 'desc', 'paged' => $paged ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
Here's the code I'm using to make the forward and backward links:
if ( $the_query->max_num_pages > 1 ) : // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="prev-posts-link"> <?php echo get_next_posts_link( '« Previous', $the_query->max_num_pages ); // display older posts link ?> </div> <div class="next-posts-link"> <?php echo get_previous_posts_link( 'Newer »' ); // display newer posts link ?> </div> </nav> <?php endif; ?>
The links that are being generated seem to look OK:
mysite.com/news-events/page/2/ however these 404. The strange thing is, if I manaully change this link from
mysite.com/news-events/page/1/ that redirects to `mysite.com/news-events/.
I've tried re-saving my permalink structure, and changing it. I've tried disabling plugins etc, I'm really out of ideas!
Any help is appreciated, thanks.