I'm trying to get a rewrite_rules_array
rule to work and running into issues. I would like to add a rule so that when someone visits:
It essentially loads:
What really happens is that Wordpress redirects you to .
add_filter('rewrite_rules_array', function( $rules ) {
$new = array();
$new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
return array_merge( $new, $rules );
});
- I've flushed my permalinks.
view
has been added to the query_vars.
I'm trying to get a rewrite_rules_array
rule to work and running into issues. I would like to add a rule so that when someone visits:
http://domain/product/foo/bar
It essentially loads:
http://domain/product/foo?view=bar
What really happens is that Wordpress redirects you to http://domain/product/foo.
add_filter('rewrite_rules_array', function( $rules ) {
$new = array();
$new['product/(.*)/(.*)/?'] = 'index.php?pagename=$matches[1]&view=$matches[2]';
return array_merge( $new, $rules );
});
- I've flushed my permalinks.
view
has been added to the query_vars.
1 Answer
Reset to default 0For anyone looking, the solution was:
add_action('init', function() {
add_rewrite_rule(
'product/(.*)/(.*)/?',
'index.php?product=$matches[1]&view=$matches[2]',
'top'
);
});
page
post type? Also- just useadd_rewrite_rule
hooked toinit
if you’re just adding rules and not manipulating existing rules or reordering. – Milo Commented Nov 14, 2018 at 23:00