For what it’s worth, I just gave up on the ‘__not_in’ approach and went with the following somewhat sneaky solution:
//Create the exclusion rule
$new_tax_query = array(
array(
'taxonomy' => 'x_category',
'field' => 'slug',
'terms' => array('y-slug'),
'operator' => 'NOT IN',
)
);
//If there is already a tax_query, 'AND' our new rule with the entire existing rule.
$tax_query = $query->get('tax_query');
if(!empty($tax_query)) {
$new_tax_query = array(
'relation' => 'AND',
$tax_query,
$new_tax_query
);
}
// var_dump($new_tax_query);
$query->set('tax_query', $new_tax_query);
Related Posts:
- Retrieve posts by term id custom query
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- Display category posts grouped by taxonomy
- Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
- pre_get_posts with tax_query causes empty result
- restrict_manage_posts not working in 3.3.1
- pre_get_posts OR relation between taxonomy and author
- Filter all queries with a specific taxonomy
- wp_query orderby title and meta key value (WP3.1)
- Help With issue on pre_get_posts filter in taxonomy
- Looping Through Custom Tax Terms and Displaying All Posts For Each
- tax_query not working on main query
- How to add custom taxonomy to search
- Taxonomy.php issue with search and filters
- How to List Parent Term Links for Custom Taxonomy With & Without Children?
- Search by type posts and taxonomy
- How do I sort posts by custom taxonomy?
- Recreating the hierarchy of taxonomies for a dropdown form menu?
- Custom taxonomy query not working with switch_to_blog
- $wpdb query a post type within a specific taxonomy term while ordering posts by custom meta value?
- Print terms with taxonomy and metabox value
- orderby meta_value breaks taxonomy term archives
- Checkbox onclick filtering on the same page
- WordPress Tag or Custom Taxonomy Return All Posts if has that Word in Post Title
- Custom Taxonomy Not Working When added to WordPress Search
- A way to query custom taxonomies by name
- get the taxonomies terms associated with users
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Removing “s” from search with custom parameters
- Rewrite Rules returning wrong data
- Sorting main query by custom taxonomy slug
- WordPress Custom post query sorting does not work
- List related terms + taxonomies
- Search Query for Multiple Terms In Same Taxonomy
- Exclude taxonomy term from all loops, but having it on widget
- Get list of taxonomies associated with users
- query_posts that have custom taxonomy and limiting what shows based on the taxonomy
- Several taxonomy query (like filter)
- pre_get_posts post_meta event
- Taxonomy archive template that shows posts from more than one taxonomy
- how to access the $query variable inside taxonomy-xxx.php template file?
- Displaying Posts Attached to Custom Taxonomy Terms
- Update Custom Taxonomy Value for a post based on custom date field
- Get 1st parent category id from post
- How to get the term description in a taxonomy term archive query?
- making an index from custom taxonomies and tags of posts (not hierarchical taxonomy)
- Query Multiple Custom Taxonomies
- Amend taxonomy to search in wordpress admin
- Main query disturb pre_get_post by category query
- Add terms to a taxonomy archive from within the same taxonomy
- Random order not working correctly when using default loop + $query->set
- How to exclude woocommerece product category in search results?
- Query by multiple custom taxonomies
- Pre_get_post custom taxonomy combined with custom fields?
- WP Query : strange behaviour with multiple no-hierarchical tax
- WordPress search form and search result through ACF field in custom taxonomy
- Include attachments with a custom taxonomy in search
- Query pages by child term
- Can I use multi (sub) levels of relation (AND | OR) on custom query?
- Tax Query not working
- Custom taxonomy – query returns an error
- How to perform a search inside a specific taxonomy category
- Adding a query var to taxonomy term archive – gets redirected to the other taxonomy archive page
- Exclude 2 in 3 terms of A Taxonomy from all Archives
- add_query_arg to look up page title
- How can I query for all values of a custom taxonomies?
- query grandchildren taxonomy terms
- get_the_terms inside save_post gives old terms
- Querying posts globally based on custom taxonomy with its own taxonomymeta table
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
- Hide empty categories on widget
- Include posts under a custom taxonomy in author.php
- Using wp_query is it possible to orderby taxonomy?
- “tax_query” parameter not working with WP_Query
- How do I exclude a custom taxonomy from the post loop
- get_posts assigned to a specific custom taxonomy term, and not the term’s children
- How can I get only parent terms?
- How to modify a taxonomy that’s already registered
- Change order of Custom Taxonomy List
- Get the the top-level parent of a custom taxonomy term
- get_the_term_list without links in 3.1
- Inserting terms in an Hierarchical Taxonomy
- get_terms – only top level
- Custom taxonomy terms not showing as list Gutenberg Editor
- Altering the appearance of custom taxonomy inputs
- How to only list the child terms of a taxonomy and not their parents?
- Get term SLUG by term ID
- Is ACF being a honey trap? [closed]
- Get term name from term ID?
- Check if Current Category has Children
- How to use taxonomies on attachments with the new Media Library?
- Hierarchical taxonomy UI
- WordPress taxonomy radio buttons
- How to prevent new terms being added to a custom taxonomy?
- Custom taxonomy, get_the_terms, listing in order of parent > child
- How to remove the tag cloud from custom taxonomy admin page?
- custom taxonomy and pages rewrite slug conflict gives 404
- Inserting a term into a custom taxonomy
- Count posts in custom taxonomy
- How to add images to taxonomies?