[wp-trac] [WordPress Trac] #32409: paginate_links() shows 404 on custom post type archive

WordPress Trac noreply at wordpress.org
Fri May 15 08:01:55 UTC 2015


#32409: paginate_links() shows 404 on custom post type archive
--------------------------+-----------------------------
 Reporter:  Kuzmanov      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 This is happening only on custom post type archive pages.

 The scenario is this:
 * If I remove the `posts_per_page` argument from `WP_Query` it reads the
 value from `Settings > Reading` and works fine.
 * If the value of `posts_per_page` in `WP_Query` is bigger or equal than
 the value in `Settings  > Reading` it works fine.
 * '''The problem:''' If the value of `posts_per_page` in `WP_Query` is
 smaller than the value in `Settings  > Reading` it shows page not found on
 every `/page/x`.

 ||             ||= Settings =||= WP_Query =||
 ||= OK   =||  5  || / ||
 ||= OK   =||  5  ||  5 or 5+ ||
 ||= NOT OK =||  5  || 4 or smaller ||

 Here is my query:
 {{{
 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
 $wp_query = new WP_Query( array(
         'post_type' => 'custom_post_type_name',
         'post_status' => 'publish',
         'paged' => $paged,
         'posts_per_page' => 5,
 ) );
 }}}

 And here is the pagination:

 {{{
 global $wp_query;
 $total = $wp_query->max_num_pages;

 if ( $total > 1 )  {
         // get the current page
         if ( !$current_page = get_query_var('paged') ) {
                 $current_page = 1;
         }

         echo paginate_links(array(
                 'current'  => $current_page,
                 'format'    => '/page/%#%',
                 'total'    => $total,
                 'mid_size' => 4,
                 'type'     => 'list',
                 'next_text' => 'next posts',
                 'prev_text' => 'prev posts'
         ));
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32409>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list