I have a static front page in WordPress and I want to use a city name in the permalink so that I can change the contents of the page on the basis of the detected city. However, when I try to add a rule, it takes me to the wrong page. Here is a sample of the code I’m trying to use:
$wp_rewrite->add_rule('^city-([^/]*)/?$','index.php?cityNameParma=$matches[1]','top');
It’s for a page which will display businesses directory listings. Upon clicking I added a new rule
which should allow inner pages to work as intended:
$wp_rewrite->add_rule('^city-([^/]*)/wpbdm-category/([^/]*)/?$','index.php?wpbdm-category=$matches[2]&cityNameParma=$matches[1]','top');
I then get the city name from the URL with
$wp_query->query_vars['cityNameParma'];
The only problem that remains is how to get the value when a static home page is called and how I send the parameter value as I have done for inner pages.
Kindly help me out as I have melted my brain.
i think you also have to add your new parameter to the accepted query-params:
then you can access it in your template files like you described: