Taxonomy page template changing when using query variables

I’m hoping someone can help me fill in the gaps in my understanding of page templates and query vars:

I’ve registered a custom taxonomy ‘stream’, and have set up a page template for that taxonomy, taxonomy-stream.php. The page template lists an archive of posts that are using the respective taxonomy term. Everything there works fine.

I’m trying to add a filter to the sidebar to allow the user to narrow down the taxonomy archive of posts based on Categories. I am finding that if I add a query var to the URL (?category_name=text, for example) that the page template switches from my taxonomy-stream.php template to archive.php. My goal, however, is for the ?category_name=test query var to limit the results of the taxonomy archive.

The query var itself seems to be changing the page template to archive.php instead of keeping it on the taxonomy-stream.php template. What am I missing here?

1 Answer
1

The problem is that category_name is a reserved keyword for the built-in categories for posts. Almost anything category_* is reserved. You can find a list of reserved keywords at the following url:

https://codex.wordpress.org/Reserved_Terms

This includes, but is not limited to:

  • cat
  • category
  • category__and
  • category__in
  • category__not_in
  • category_name
  • term
  • terms

Behind the scenes it sees that you’re using the category_name reserved keyword. It knows categories are a taxonomy of posts and switches to the archive.php template. If the archive.php template did not exist it would default to index.php and try to load posts looking for anything in the test category (taxonomy).

Leave a Comment