Ok, I've read over pretty much every answer to this question, but my situation must be unique somehow.
What I'm attempting to do is straightforward in theory.
- CPT: resource
- Tax1: resource_type
- Tax2: industry
When I register the CPT I have set the following:
'rewrite' => array(
'slug' => 'resources/%resource_type%',
'with_front' => false
),
'with_front' => false
because the standard posts is using a base.
I also have a page of example.com/resources
with a template of page-resources.php
.
When I register Tax1 I have set the following:
'rewrite' => array(
'slug' => 'resources',
'with_front' => false
)
I have a resource_type
term named white-papers
.
This produces my first desired outcome of a permalink that looks like
example.com/resources/white-papers/
for a taxonomy archive page using taxonomy-resource_type.php
.
This is where things getting tricky. What I'm attempting to do is add a second taxonomy (Tax2) and create another archive page with a permalink of:
example.com/resources/white-papers/enterprise
This archive is a filtered archive of sorts in that it should show just the post that are of resource_type = white-papers
AND industry = enterprise
.
Instead I get 404
.
But if I try to a URL with a query of example.com/index.php?post_type=resource&resource_type=white-papers&industry=enterprise
I get my desired filtered archive page.
Also, and I'm not sure if its relevant to the issue or not, but I have this function running:
function resources_cpt_generating_rule($wp_rewrite) {
$rules = array();
$terms = get_terms( array(
'taxonomy' => 'resource_type',
'hide_empty' => false,
) );
$post_type = 'resource';
foreach ($terms as $term) {
$rules['resources/' . $term->slug . '/([^/]*)$'] = 'index.php?post_type=' . $post_type. '&resource_type=$matches[1]&name=$matches[1]';
}
// merge with global rules
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'resources_cpt_generating_rule');
What I need help with is the rewrite rules for accomplishing this.
Any help is greatly appreciated in advance!