I am trying to paginate some records in Wordpress 4.1. I have a custom post type (events) and a category called 'training'. I have created a custom category template (category-training.php) which I use to make the query_posts().
I have the following in category-training.php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'events', 'cat' => "20", //(The training category id) 'paged' => $paged, ); query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> the_title();<?php endwhile; $big = 999999999; // need an unlikely integer global $wp_query; echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages ) ); endif;
When I go to my site at www.site.com/category/training/
I see the first 12 records I expect. The pagination links are below and indicate the correct number of pages. However when I click to go to another page (or manually enter the url) I am taken to a 404 page.
The crux of the problem seems to be when I set the post type to events. If I take that out and put a ton of regular posts in the training category, the pagination works fine. I also notice that if I then revert to specifying post_type I can sometimes get to page one or two - what I think is happening is that the pages are being set up according to the expected category posts but not including other post_types = so if there was 36 normal posts in the category - I could get to page 3 (at 12 per page).