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?


See: 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.

  • Yup, I'll post an answer soon. I'm only using archive.php and had added conditionals to load the specifix taxo template... But the icing on the cake: was adding an extra url-param that only applies when the archives are being filtered. Without that, there was no way to distinguish between the ?country being applied as a filter to the archive output and ?country being applied to call the template/partial
    – admcfajn
    Nov 7 '17 at 21:40

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.