rewrite rules – rewriteRules WP6
I’ve got a custom post type „prods“ which is set up this way
function book_cpt() {
$args_prods = array(
'labels' => array('name'=> 'Prods'),
'public' => true,
'menu_icon' => 'dashicons-prods',
'supports' => array(
'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes',
),
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array(
'slug' => sprintf( '%s/&prods_categories&', 'prods' ),
'with_front' => false,
),
);
register_post_type( 'prods', $args_prods );
add_action( 'init', 'book_cpt' );
and following rewriteRules function, which worked fines in WP5 but in WP6 not work anymore. I already debugged but WP is not running through.
function prods_rewrite_rule( $rules ) {
$newRule1 = sprintf( '%s/([^/]+)/(?:(?!\bpage\b).)+/([^/]+)/?$', 'prods' ); // matches products (products) but let WordPress do taxonomy pagination stuff correctly
$newRule2 = sprintf( '%s/([^/]+)/([^/]+)/(?:(?!\bpage\b).)+/([^/]+)/?$', 'prods' );
$newRules = array();
$newRules[$newRule1] = 'index.php?prods=$matches[2]';
$newRules[$newRule2] = 'index.php?prods=$matches[3]';
$rules->rules = $newRules + $rules->rules;
}
add_filter( 'generate_rewrite_rules', 'prods_rewrite_rule' );
also tried this add_filter(‚rewrite_rules_array‘,’……………
The Slug is made of multilevel categories for example https://domain.com/prods/cat1/subcat2/prodsname/
I would like to end up with the slug https://domain.com/prods/cat1/subcat2/prodsname/ on my CPT detail page and that is currently no longer possible, but it worked wonderfully in WP5 with the prods_rewrite_rule( ) function. The CPT registration is correct and the placerholder permalink is correct in the wp-admin: https://domain.com/prods/&prods_categories&/prodsname/ because the product should not only be reached in one category, even in all categories . The detail page should be reached in all selected categories correctly, for example evene this https://domain.com/prods/cat2/subcat3/prodsname/
Thank for replies
Leave an answer