This Q is a follow up to this answer on the Q: “How to exclude a specific term for the search?”.
4 ways to filter out posts that have a specific term
Type | Pro | Contra
--------------------------------------------------------
Run a new query | Easy to implement | Add. Queries
| Add. time to execute the DB call + processing the parsing of the results
Inside the loop | Easy to implement | Sometimes Add. Queries
| Add. time to execute
Modify the query | Full control | Hard to implement
| Needs a lot of knowledge (preparing, DB interaction)
Add new query parts | No perform. impact | Hard to get around
| Secure
| Full core support
The first type imho is not an option. The “Types” 2 & 3 are already answered in the other Q and both still have some backdraws.
Question:
- How to add an additional
tax_query
argument to the main query using (for e.g.) thepre_get_posts
filter? - Do you know additional ways to modify the main query?
You can set the taxonomy query for the main query using pre_get_posts:
If
tax_query
is already set and you need to modify it instead, you can grab and then add to the$tax_query
array.