Here's the setup.
I have a custom post type 'Businesses'. I have a custom taxonomy 'Display Category'. And I have a second custom taxonomy 'Filters'
Both taxonomies are set to work with the custom post type.
I am trying to get a url structure that looks like this
www.domain.com/businesses/display category term/filter term
There are only 3 possible choices for the Display Category, those are eat,stay, and play. The Filters then have quite a few choices. so here is the rewrite rule I have so far but it's not working and I'm not sure why.
function test_add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
'businesses/(eat|stay|play)/(.+)/?$' => 'index.php?post_type=businesses&display_category=' . $wp_rewrite->preg_index(1) . '&filters=' . $wp_rewrite->preg_index(2),
'businesses/(eat|stay|play)/?$' => 'index.php?post_type=businesses&display_category=' . $wp_rewrite->preg_index(1)
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( 'generate_rewrite_rules', 'test_add_rewrite_rules' );
I am using a rewrite rule inspector plugin so I know the rules are being added. But they are not returning the pages I want. I found this article about rewrite rules and it helped me get this far but I am stuck now. Any help would be greatly apprecieated!
Update
Here is the above code but instead using the add_rewrite_rule function. I have hooked in into init for now because the generate_rewrite_rules hook was firing too late for the new rules to be save. I also realized that I will need to get the paged rules to work as well but I'm not sure how to do that.
function test_add_rewrite_rules() {
global $wp_rewrite;
add_rewrite_rule('businesses/(eat|stay|play)/(.+)/?$', 'index.php?post_type=businesses&display_category=$matches[1]&filters=$matches[2]', 'top');
add_rewrite_rule('businesses/(eat|stay|play)/?$', 'index.php?post_type=businesses&display_category=$matches[1]', 'top');
}
add_action( 'init', 'test_add_rewrite_rules' );
add_rewrite_rule()
.init
should be sufficient