I have a site with multiple custom taxonomies which are used for filtering posts.
One of the taxonomies has a taxonomy-%term%.php
template file.
/?country=the_country
shows the country taxonomy template
but /?topic=the_topic&country=the_country
uses the country taxonomy template as well.
Is there a simple way to avoid loading the taxonomy-country.php
template if more than one taxonomy is being queried?
I have a site with multiple custom taxonomies which are used for filtering posts.
One of the taxonomies has a taxonomy-%term%.php
template file.
/?country=the_country
shows the country taxonomy template
but /?topic=the_topic&country=the_country
uses the country taxonomy template as well.
Is there a simple way to avoid loading the taxonomy-country.php
template if more than one taxonomy is being queried?
2 Answers
Reset to default 1See: Template Hierarchy
My suggestion would be to move away from term-specific template files in this case, and instead use only taxonomy.php
, where in that file you can work out the logic you need to in order to render the proper output; i.e., you can then detect the use of multiple taxonomies and adjust as necessary.
The solution here was found by (as jaswrks has mentioned) removing the taxonomy-country.php
file entirely.
The contents of taxonomy-country.php
are then loaded conditionally within taxonomy.php
Custom post_types & taxonomies have an option to "rewrite" the urls. In this case, the same url parameters that are filtering the taxonomy archives were sometimes colliding with this url-schema and causing unwanted results.
The simple answer would be to disable rewriting the urls of the problem taxonomies.
But a cleaner option turned out to be to
remove_filter( 'template_redirect', 'redirect_canonical' );
... which can be used to disable the rewrite
attribute from custom post_types or taxonomies