I have the following rewrite tags defined:
// ADD REWRITE TAG FOR 'VEHICLE MAKES'
add_rewrite_tag('%make%','([^&]+)');
// ADD REWRITE TAG FOR 'BODY STYLES'
add_rewrite_tag('%body-style%','([^&]+)');
// ADD REWRITE TAG FOR 'OTHER TOPICS'
add_rewrite_tag('%topic%','([^&]+)');
I’m trying to create a custom rewrite for each one of these that can apply to any page the variables exist.
I’ve been reworking the WP example in the documentation with no luck.. This rewrite is for ‘Vehicle Makes’.
I’m aiming for WP to interpret the following:
http://example.com/make/abc
as
http://example.com?make=abc
and the same pattern for
http://example.com?body-style=abc
& http://example.com?topic=abc
I can’t seem to get the following to work no matter how much I try
add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','index.php?page_id=12&food=$matches[1]&variety=$matches[2]','top');
Any and All help is appreciated!
Have you tried adding the third parameter to that call?
add_rewrite_tag( '%make%', '([^/]+)', 'make=' );
The way of using
add_rewrite_rule
function is given below:init
hookquery_vars
filter to make the new rewrite available in thequery_vars
Here is the code snippet
Now, go to permalink settings page, and click on
Save Changes
to flush the rewrite rules.Before asking any question here, please try to find it out yourself. In case of wordpress you should look at http://codex.wordpress.org/ first.
Most of the answers are available already.
The piece of code you are looking for is a function flush_rewrite_rules().
Ref: Rewrite Rules