Should I use ‘tag’, ‘cat’ and ‘tax_query’ parameters together in a WP_Query?

Question

What I’m building

I’m developping a plugin. I’m currently filtering the posts by tags and categories (tag and category_name WP_Query parameters) with values given in a shortcode. I want to add the possibility to filter by custom taxonomy too.

What I know (correct me if I’m wrong)

  • When I use tag, cat and tax_query parameters in a WP_Query, the relation is AND between them.
  • When I set an empty string as value for tag or cat, the query ignores it.
  • tax_query can have AND and OR relation types set inside of it.

My questions

  1. Is it good to use all three parameters together in term of speed and optimization? Or is it best to use only tax_query (or is it the same ?).
  2. Can I use tax_query only for that query? My categories and tags values can be empty strings when the user don’t want to filter by those taxonomies.
  3. If 2. answer’s is yes, what ‘taxonomy’ value should I enter for category and tags taxonomies ?

Thank you 🙂

0
, , , , Camille V. 4 years 2020-05-17T05:10:22-05:00 0 Answers 93 views 0

Leave an answer

Browse
Browse