WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a taxonomy search form and the link output is


But i want it to be rewrited as



# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]

# END WordPress

It didn't work:

RewirteRule ^wp/cityid/([0-9]+)$ ?cityid=$1 [L]

It didnt work either (from wp codex):

add_action('generate_rewrite_rules', 'geotags_add_rewrite_rules');

    function geotags_add_rewrite_rules( $wp_rewrite ) 
      $new_rules = array( 
         'cityid/(.+)' => 'index.php?cityid=' .
           $wp_rewrite->preg_index(1) );

      //​ Add the new rewrite rule into the top of the global rules array
      $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

Any help please?

share|improve this question
up vote 1 down vote accepted

Try this code:

function geotags_add_rewrite_rules($wp_rewrite_rules) {
    global $wp_rewrite;

    $rule_key = '%cityid%';
    $url_pattern = '([^/]+)';
    $query_string = 'cityid=';

    $wp_rewrite->add_rewrite_tag($rule_key, $url_pattern, $query_string);

    $url_structure = $wp_rewrite->root . "cityid/$rule_key/";
    $rewrite_rules = $wp_rewrite->generate_rewrite_rules($url_structure);

    $wp_rewrite_rules = $rewrite_rules + $wp_rewrite_rules;
    return $wp_rewrite_rules;

add_filter('rewrite_rules_array', 'geotags_add_rewrite_rules');

function geotags_add_query_var($query_vars) {
    array_push($query_vars, 'cityid');
    return $query_vars;


NOTE: Remember to save permalinks so your new rule is picked up by WP.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.