title: Wordpress Custom Post type Category View with Pagination
body: <p>I have a custom post type 'charters' and within my category.php page I have a loop pulling in 'charter' posts for the current category id.  I have a custom pagination setup displaying page numbers when I click page 2 link, it goes to URL /page/2 which displays a 404 error.  I can't figure out why I am getting the 404.  If I adjust my posts per page the pagination updates and displays the correct number of pages but the links do not show up.</p>
  
  <p><strong>Category.php Code:</strong></p>
  
  <pre><code> &lt;?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  
    $product_args = array(
        'post_type' =&gt; 'charters',
        'posts_per_page' =&gt; 10, //the same as the parse_query filter in our functions.php file
        'paged' =&gt; $paged,
        'page' =&gt; $paged,
        'cat' =&gt; $cat
      );
  
    $product_query = new WP_Query( $product_args ); ?&gt;
  
    &lt;?php if ( $product_query-&gt;have_posts() ) : ?&gt;
  
      &lt;!-- the loop --&gt;
      &lt;?php while ( $product_query-&gt;have_posts() ) : $product_query-&gt;the_post(); ?&gt;
        &lt;article class="loop"&gt;
          &lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt;
          &lt;div class="content"&gt;
            &lt;?php the_excerpt(); ?&gt;
          &lt;/div&gt;
        &lt;/article&gt;
      &lt;?php endwhile; ?&gt;
      &lt;!-- end of the loop --&gt;
  
  
      &lt;!-- pagination here --&gt;
      &lt;?php
         if (function_exists( 'custom_pagination' )) :
            custom_pagination( $product_query-&gt;max_num_pages,"",$paged );
        endif;
     ?&gt;
  
  
    &lt;?php wp_reset_postdata(); ?&gt;
  
    &lt;?php else:  ?&gt;
      &lt;p&gt;&lt;?php _e( 'Sorry, no posts matched your criteria.' ); ?&gt;&lt;/p&gt;
    &lt;?php endif; ?&gt;
  </code></pre>
  
  <p><strong>Functions.php Code:</strong></p>
  
  <pre><code>function prefix_change_cpt_archive_per_page( $query ) {
  
      //* for cpt or any post type main archive
      if ( $query-&gt;is_main_query() &amp;&amp; ! is_admin() &amp;&amp; is_post_type_archive( 'product' ) ) {
          $query-&gt;set( 'posts_per_page', '10' );
      }
  
  }
  add_action( 'pre_get_posts', 'prefix_change_cpt_archive_per_page' );
  
  
  function prefix_change_category_cpt_posts_per_page( $query ) {
  
      if ( $query-&gt;is_main_query() &amp;&amp; ! is_admin() &amp;&amp; is_category( 'test-category' ) ) {
          $query-&gt;set( 'post_type', array( 'product' ) );
          $query-&gt;set( 'posts_per_page', '2' );
      }
  
  }
  add_action( 'pre_get_posts', 'prefix_change_category_cpt_posts_per_page' );
  
  
  
  function custom_pagination( $numpages = '', $pagerange = '', $paged='' ) {
  
    if (empty($pagerange)) {
      $pagerange = 2;
    }
  
  
    global $paged;
    if (empty($paged)) {
      $paged = 1;
    }
    if ($numpages == '') {
      global $wp_query;
      $numpages = $wp_query-&gt;max_num_pages;
      if(!$numpages) {
          $numpages = 1;
      }
    }
  
  
    $pagination_args = array(
      'base'            =&gt; get_pagenum_link(1) . '%_%',
      'format'          =&gt; 'page/%#%',
      'total'           =&gt; $numpages,
      'current'         =&gt; $paged,
      'show_all'        =&gt; False,
      'end_size'        =&gt; 1,
      'mid_size'        =&gt; $pagerange,
      'prev_next'       =&gt; True,
      'prev_text'       =&gt; __('&amp;laquo;'),
      'next_text'       =&gt; __('&amp;raquo;'),
      'type'            =&gt; 'plain',
      'add_args'        =&gt; false,
      'add_fragment'    =&gt; ''
    );
  
    $paginate_links = paginate_links($pagination_args);
  
    if ($paginate_links) {
      echo "&lt;nav class='custom-pagination'&gt;";
        echo "&lt;span class='page-numbers page-num'&gt;Page " . $paged . " of " . $numpages . "&lt;/span&gt; ";
        echo $paginate_links;
      echo "&lt;/nav&gt;";
    }
  </code></pre>
  
  <p>My Permalink Settings are set to "Post Name" I have a feeling this has something to do with rewrites but I can not figure out how to get the page urls to work correctly.  An example of my categories are as follows:</p>
  
  <p><em>/category/long-beach/<br>
  /category/san-diego/</em></p>