[wp-trac] [WordPress Trac] #15551: Custom post type pagination redirect

WordPress Trac noreply at wordpress.org
Tue May 6 02:03:49 UTC 2014


#15551: Custom post type pagination redirect
--------------------------+-----------------------
 Reporter:  cbsad         |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:
Component:  Query         |     Version:  3.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+-----------------------
Changes (by ianarmstrong):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 I can confirm that this is still very much an issue in 3.9.x when
 generating a custom post type archive, applying pagination, and using
 permalink rewrites.

 Case: a custom post type for items in a collection.

 You want this:
 ../collection/home-decor/page/2/

 You click and get this:
 ../collection/home-decor/

 It happens every single time.

 It was fixed using:


 {{{
 // Disable canonical urls for pagination
 add_filter( 'redirect_canonical','custom_disable_redirect_canonical' );
 function custom_disable_redirect_canonical( $redirect_url ){
     global $post;
     $ptype = get_post_type( $post );
     if ( $ptype == 'items' && is_archive() ) $redirect_url = false;
     return $redirect_url;
 }
 }}}

 The original loop was basically:


 {{{
 /**
  * The logic for displaying a collection gallery
  */

 wp_reset_postdata();
 global $post;

 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 $my_items = array(
     'post_type' => 'items',
     'numberposts' => -1,
     'orderby' => 'title',
     'order' => 'ASC',
     'posts_per_page'   => 12,
     'paged' => $paged
 );

 $my_postlist = new WP_Query( $my_items );

 if($my_postlist->have_posts()) : while($my_postlist->have_posts()) :
 $my_postlist->the_post();

     // Build your post loop here

 endwhile;

 else :

     // Build your contingency content here

 endif;
 }}}

 The actual loop was using a meta-query out of wp-types but that wasn't the
 issue. The issue was a forced canonical redirect from the page permalink
 to the root.

 Doesn't matter if I use default permalinks, WP_PageNavi, or Hybrid Core;
 obviously. While I never have to tear my hair out over this again, it's a
 horribly user-unfriendly issue.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/15551#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list