WP Rewrite issue

I’m trying to build this structure:

for single page:

Read More
www.example.com/london/restaurants/monrooe/

where:

  • “london” is a query var
  • “restaurants” is a category
  • “monrooe” is the post name.

How can I do it?

That’s code I have so far:

function setup_city_var($vars){     
  $vars[] = "city";
  return $vars;
}


function create_custom_rewrite_rules() {

  global $wp_rewrite;
  $rewrite_tag = '%city%';

  // Add the rewrite tokens
  $wp_rewrite->add_rewrite_tag( $rewrite_tag, '(.+?)', 'city=' );

  // Define the custom permalink structure
  $rewrite_keywords_structure = $wp_rewrite->root . "$rewrite_tag/%pagename%";

  // Generate the rewrite rules
  $new_rule = $wp_rewrite->generate_rewrite_rules( $rewrite_keywords_structure );

  $wp_rewrite->rules = $new_rule + $wp_rewrite->rules;

  return $wp_rewrite->rules;
} // End create_custom_rewrite_rules()

It doesn’t work, it’s a 404

Any Ideas?

Thanks

Related posts