[wp-trac] [WordPress Trac] #23111: Possible 404 whend paging Category archives
WordPress Trac
noreply at wordpress.org
Sun Feb 4 18:34:09 UTC 2024
#23111: Possible 404 whend paging Category archives
--------------------------+------------------------
Reporter: mendelk | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Permalinks | Version: 3.5
Severity: normal | Resolution: duplicate
Keywords: | Focuses:
--------------------------+------------------------
Comment (by majhes):
Please try using code below:
add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules'
);
function vipx_filter_category_rewrite_rules( $rules ) {
$categories = get_categories( array( 'hide_empty' => false ) );
if ( is_array( $categories ) && ! empty( $categories ) ) {
$slugs = array();
foreach ( $categories as $category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
if ( 0 == $category->category_parent ) {
$slugs[] = $category->slug;
} else {
$slugs[] = trim( get_category_parents(
$category->term_id, false, '/', true ), '/' );
}
}
}
if ( ! empty( $slugs ) ) {
$rules = array();
foreach ( $slugs as $slug ) {
$rules[ '(' . $slug .
')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] =
'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] =
'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')(/page/(\d+)/?)?$' ] =
'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}
IMPORTANT EDIT: There was a bug in pagination, pages 10+ didn't work
properly.
Now fixed: (\d)+ changed to (\d+) .
Hope this will be helpful :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/23111#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list