Should I use ‘tag’, ‘cat’ and ‘tax_query’ parameters together in a WP_Query?
What I’m building
I’m developping a plugin. I’m currently filtering the posts by tags and categories (
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
tax_queryparameters in a WP_Query, the relation is AND between them.
- When I set an empty string as value for
cat, the query ignores it.
tax_querycan have AND and OR relation types set inside of it.
- 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 ?).
- Can I use
tax_queryonly for that query? My categories and tags values can be empty strings when the user don’t want to filter by those taxonomies.
- If 2. answer’s is yes, what ‘taxonomy’ value should I enter for category and tags taxonomies ?
Thank you 🙂