rewriteRules WP6 | ProjectDMC.org Deutsch

[ad_1]

I’ve got a custom post type „products“ which is set up this way

$args_products = array(
'labels' => array('name'=> 'Product Category'),
'public' => true,
'menu_icon' => 'dashicons-products',
'supports' => array(
'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes',
),
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array(
'slug' => sprintf( '%s/&products_categories&', 'products' ),
'with_front' => false,
),
);

register_post_type( 'products', $args_products );

an following rewriteRules function, which in WP6 does not work anymore. I already debugged but WP is not running through.

function products_rewrite_rule( $rules ) {
$newRule1 = sprintf( '%s/([^/]+)/(?:(?!\bpage\b).)+/([^/]+)/?$', 'products' ); // matches products (products) but let WordPress do taxonomy pagination stuff correctly
$newRule2 = sprintf( '%s/([^/]+)/([^/]+)/(?:(?!\bpage\b).)+/([^/]+)/?$', 'products' );
$newRules = array();
$newRules[$newRule1] = 'index.php?products=$matches[2]';
$newRules[$newRule2] = 'index.php?products=$matches[3]';
$rules->rules = $newRules + $rules->rules;
}
add_filter( 'generate_rewrite_rules', 'products_rewrite_rule' );

also tried this add_filter(‚rewrite_rules_array‘,’……………

The Slug is made of multiple categories for example

which should work.

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer