One of the examples using add_rewrite_rule
function in wordpress is
add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','index.php?page_id=12&food=$matches[1]&variety=$matches[2]','top');
I can understand where matches[1] is and where matches[2] is, but is there any way to change these matches, something like:
add_rewrite_rule('^nutrition/([^/]*)/([^/]*)/?','index.php?page_id=12&food=' . f1($matches[1]) . '&variety=' . f2($matches[2]),'top');
Where f1
is a function of matches[1]
and f2
is a function of matches[2]
Thank you very much.
Edit 1:
This is a very general question with the objective to understand wordpress add_rewrite rule. One example of f1 and f2 function is
function f1($string) {
if (strpos($string, '/america/')) {$string .= '-1';}
esleif (strpos($string, '/england/')) {$string .= '-2';}
return $string;
}
f2 was a similar function to f1.