how to pass city name in parmalink structure of wordpress

Go To StackoverFlow.com

2

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.

2012-04-04 07:56
by kashif


0

i think you also have to add your new parameter to the accepted query-params:

function my_query_vars( $qvars )
{
    $qvars[] = 'cityNameParma';
    return $qvars;
}
add_filter('query_vars', 'my_query_vars');

then you can access it in your template files like you described:

global $wp_query;
$wp_query->query_vars['cityNameParma'];
2012-04-04 08:17
by pkyeck
yes i have alredy have the method inplace and it is working properly as intended but my problem is that when i add it for home page it display me 404 page not foun - kashif 2012-04-04 08:49
Ads