Consider the two following custom post types:
- Museums
- Bakeries
With one shared taxonomy:
- Region
I’m using rewrite rules to improve the URL structure, so I can serve pages to visitors such as:
- https://myurl.com/museums/london (all museums in London)
- https://myurl.com/bakeries/birmingham (all bakeries in Birmingham)
- https://myurl.com/bakeries/london/aok_kitchen (a specific bakery in London)
Here are the rewrite rules:
function my_url_rewrite_rule() {
add_rewrite_rule( '^museums/([^/]+)/?$',
'index.php?taxonomy=region&post_type=museums&term=$matches[1]', 'top' );
add_rewrite_rule( '^museums/([^/]+)/page/([0-9]+)?$',
'index.php?post_type=museums&genre=$matches[1]&paged=$matches[2]', 'top' );
add_rewrite_rule( '^bakeries/([^/]+)/?$',
'index.php?taxonomy=region&post_type=bakeries&term=$matches[1]', 'top' );
add_rewrite_rule( '^bakeries/([^/]+)/page/([0-9]+)?$',
'index.php?post_type=bakeries&genre=$matches[1]&paged=$matches[2]', 'top' );
}
add_action( 'init', 'my_url_rewrite_rule', 10, 0 );
I have set up my templates and everything works fine, with one exception: I can’t get the following type of pages into my sitemap:
- https://myurl.com/museums/london
- https://myurl.com/bakeries/birmingham
.. And every other combination of url+post_type+taxonomy. I can access the URLs and have working templates, but I just can’t get the sitemap to understand the new structure. This is not surprising as I’m bypassing the default url structure of WordPress. But how can I proceed to get them into the sitemap?
I’m using SEOPress (Pro), but I’ve also tried with Yoast.
Thanks!