I am creating a custom tours and travel theme in which I have created custom post type Cities, Locations, Destinations and i am using custom permalink structure. /%category%/%postname%/
So now I want to append a state name or district name before that city, destination or location name. Let me make it more clear by giving you an example .
The current url structure is like this. http://test.com/custom_post_type_slug/post_name_slug
And how I want it to be like this. http://test.com/Custom_dynamic_string/custom_post_type_slug/post_name_slug Right now i am doing something like this
function add_places_rewrite_tags(){
add_rewrite_tag('%district%','([^/]+)');
}
add_action( 'init', 'add_places_rewrite_tags' );
add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
add_rewrite_rule(
"/([^/]+)/hotel/([^/]+)/?",
'index.php?post_type=hotel&district=$matches[1]&p=$matches[2]',
'top'
);
add_filter( 'query_vars', 'custom_query_vars' );
}
function custom_query_vars( $query_vars )
{
$query_vars[] = 'district';
return $query_vars;
}
but it's still not giving me the desired results and i am also using a plugin to analyze the re-wright rules