• Hey There,

    I am working on a custom query for a blog category. What I want to do is query posts from an additional category on an existing category page. I am trying to alter the default query to accomplish this. Here is the code I am using.

    //add news posts to blog category query
    add_action( 'pre_get_posts', 'custom_query_vars' );
    function custom_query_vars( $query ) {
      if ( is_category( $blog ) && $query->is_main_query() ) {
        $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    	         $query->set( 'post_type', 'any' );
    	         $query->set( 'cat', '228,19' );
    	         $query->set( 'orderby', 'date' );
    	         $query->set( 'posts_per_page', 10 );
    	         $query->set ( 'paged', $paged );
    	         $query->set ( 'order', 'DESC');
      	}
      return $query;
    }

    The pagination seems to be working fine, and the posts from both categories are being pulled, until I get to around page 70 (where the posts count from the original category would end). From there, pages 71 and on (should go up to page 600 or so accounting for both categories) are all 404 errors. The additional pages do seem to appear in the pagination, they’re just not being generated.

  • The topic ‘Custom Category Query Pagination Issue’ is closed to new replies.