[wp-trac] [WordPress Trac] #15551: Custom post type pagination redirect
WordPress Trac
noreply at wordpress.org
Tue May 27 01:46:52 UTC 2014
#15551: Custom post type pagination redirect
--------------------------+-----------------------------
Reporter: cbsad | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Future Release
Component: Query | Version: 3.1
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+-----------------------------
Changes (by wonderboymusic):
* keywords: => needs-patch
* milestone: => Future Release
Comment:
This is super obnoxious. You need to do 2 things when you want to use
`page/[0-9]+` in the URL for a CPT:
{{{
// filter _wp_link_page() in the most ghetto way possible
add_filter( 'wp_link_pages_link', function ($link) {
if ( preg_match( '#whatever/([^/]+)/([0-9]+?)/#', $link, $match )
) {
$link = str_replace( $match[0],
"whatever/{$match[1]}/page/{$match[2]}/", $link );
}
return $link;
} );
// shove your rules in there somehow
add_filter( 'rewrite_rules_array', function ($rules) {
$mine = array(
'whatever/([^/]+)/page/([0-9]+?)/?$' =>
'index.php?whatever=$matches[1]&page=$matches[2]',
);
return array_merge( $mine, $rules );
} );
}}}
Notice, the query var has to be `page`, not `paged` - after that, you can
at least view the page, but it will redirected from `page/2/` to `2/`
If someone works through the headache and creates a patch, we can do this
in 4.0
--
Ticket URL: <https://core.trac.wordpress.org/ticket/15551#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list