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

WordPress Trac wp-trac at lists.automattic.com
Tue Nov 23 21:50:06 UTC 2010


#15551: Custom post type pagination redirect
--------------------------+-------------------------------------------------
 Reporter:  cbsad         |       Owner:                 
     Type:  defect (bug)  |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  3.1            
 Severity:  normal        |    Keywords:                 
--------------------------+-------------------------------------------------
 We seem to be having a problem with a redirect on a custom post page
 (e.g., http://www.example.com/show/slug/).

 Everything on the page shows correctly. The template pulls in posts with
 the following query:
 {{{
 <?php query_posts(array('meta_key' => 'show', 'meta_value' => $show->ID,
 'paged' => get_query_var('paged'), 'caller_get_posts' => true)); ?>
 }}}

 After the posts we display pagination links (e.g.,
 http://www.example.com/show/slug/page/2/). In our rewrite rules, we
 include the following rule which should handle these URLs:
 {{{
 'show/([^/]+)/page/([0-9]{1,})/?$' =>
 'index.php?show=$matches[1]&paged=$matches[2]',
 }}}

 Instead of the page displaying and allowing us to pull in the second page
 of posts, the browser is being redirected back to the original page
 (http://www.example.com/show/slug/) with a 301. I see that this is
 happening inside the redirect_canonical function. The following code in
 wp-includes/canonical.php replaces /page/2/ with / causing the redirect:

 {{{
         // paging and feeds
         if ( get_query_var('paged') || is_feed() || get_query_var('cpage')
 ) {
                 if ( !$redirect_url )
                         $redirect_url = $requested_url;
                 $paged_redirect = @parse_url($redirect_url);
                 while ( preg_match(
 "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $paged_redirect['path']
 ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#',
 $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#',
 $paged_redirect['path'] ) ) {
                         // Strip off paging and feed
                         $paged_redirect['path'] =
 preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/',
 $paged_redirect['path']); // strip off any existing paging
                         $paged_redirect['path'] =
 preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/',
 $paged_redirect['path']); // strip off feed endings
                         $paged_redirect['path'] = preg_replace('#/comment-
 page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any
 existing comment paging
                 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15551>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list