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
- Adding Category/Tag/Taxonomy Support to Images/Media
- Large taxonomy (2000+ terms), causing WordPress to hang
- Check if current term is a child of another term
- How to pass posts_per_page and paged params query vars to custom taxonomy archive urls?
- Exclude Custom Taxonomies
- How to get the top most term (top ancestor) of a custom taxonomy child term?
- Get custom category name from ID
- Populating dropdown menu with hierarchical taxonomies
- Specifying a size when displaying an image associated with a taxonomy through ACF
- Display all posts for taxonomy term across multiple custom post types
- Getting Term ID from Term Name for WordPress Query
- How to join result of different taxonomies?
- wp_insert_term created and set for first once only
- Show all taxonomy’s terms’ posts having another taxonomy’s term in common
- Render P2P metabox per taxonomy term
- Adding content to custom taxonomy category pages
- Display formatted list of taxonomy terms with last seperator different
- Display a colour of custom taxonomy on the page
- Add attribute taxonomy through code don’t appear in admin product page
- WordPress REST API – get custom taxonomy category posts
- Pull data from MySQL and add it to terms
- Taxonomy and Page Slug Same
- Tracking the name of a custom taxonomy
- How to display custom taxonomy
- Taxonomy term breadcrumb; how?
- Transfer taxonomy to custom field
- Listing custom post type items from a couple of custom taxonomies
- Can I use get_term_children to show child terms if they exist and show something else if they don’t?
- Displaying the custom taxonomies side by side on the admin dashboard