You can setup a tax_query
with the NOT IN
operator.
WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 500,
'tax_query' => array(
'relation' => 'AND'
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'cars' ),
),
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => array( 'whatever_tag_i_dont_need' ),
'operator' => 'NOT IN',
),
),
) )
The above will request all posts in assigned to term cars
that don’t have any tags with the slug whatever_tag_i_dont_need
. There’s other comparison operator too. For more information please reference the docs below:
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
Related Posts:
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- Nested meta_query with multiple relation keys
- Posts with at least 3 tags of a list of tags
- Multiple relationship for multiple tax_query in WP_Query
- WordPress tax_query “and” operator not functioning as desired
- Conditional arguments for WP_Query and tax_query depending on if $somevar has a value
- Escaping WP_Query tax_query when term has special character(s)
- Does tax_query really beats meta_query in all situations?
- Tax_query terms ID’s using variable
- Better way to get tag stats?
- Given a WP_Query, how can I get a list of tags?
- Executing Queries in tag.php
- How to order posts tag by tag?
- post_type is ignored by WP_Query when ‘tag’ argument is included
- Why is my WP_Query not working when tax_query terms are an array?
- WP Rest API v2 return posts with specific tag
- Loop through all tags & output posts in alphabetical list
- Order posts by tags count?
- if wp_query taxonomy term have posts
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to combine tax_query and date_query in WordPress
- How to get any tag ID
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Get all posts without tags
- How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts
- Using tax_query reverses my post_type argument in a custom WP_Query
- Find all product that contain terms with %keywords% in WP_Query
- Get term by custom term meta and taxonomy
- tax_query shows no results if nothing is selected
- WP_Tax_Query with post_tag not working
- get complex results set according to category structure
- WP_Query tax_query problem
- How to add terms to my tax_query based off of the current post
- How to exclude products by tag from woocommerce shop page?
- Pagination problem after WP_Query with tag filtering
- Query all posts in a given taxonomy
- Change default ordering of taxonomy terms – pre_get_terms
- tax_query OR with empty result returns all posts
- WP_Query, tax_query and term_meta: How to?
- Is it possible to dynamically get queried term AND taxonomy?
- Empty tax_query array returns an empty array
- How can i simulate “taxonomy__in” in query?
- Get list of terms that have posts in another term
- pre_get_posts Remove tax_query Completely
- Query post from all category with same tag on 1 pages
- tax_query: Order by slug?
- reducing the amount of wp_query calls
- Meta Query relation “AND” not working
- Tax query clause inside a meta query clause?
- WordPress Related Post by tags in Single.php
- Nested tax_query that allows specified categories OR tags, but NOT other categories
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- Populate tax_query terms parameter with post term
- How to build a WP_Query using mulitple tags and using AND or OR operator between them
- Include tags in WP_Query
- Search for multiple tags?
- Display posts from only one post form in custom query and exclude in main query
- Fastest way of counting posts of a custom post type in a specific taxonomy term?
- How can I make WP_Query get posts that have a tag but also have random other tags?
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Fetch posts that match term slug first two letters (wp query)
- Is it a good idea to improve meta query performance by adding tax query?
- WP_Query | Tax_Query Relation | Unable to use ‘OR’ as it then allows all products, help me finish my query?
- WP_Query tax query part of slug
- Taxonomy Query Relation field not behaving correctly?
- Display tags with random thumbnail from selection of posts with that tag
- Query posts intersecting tags and categories
- Tax query AND/OR meta query [duplicate]
- Combining categories (Query posts with multiple taxonomy terms)
- Query with meta_query and tax_query together not working properly
- Order by most used tag
- WP Query with multiple tags by get the tags
- How to not display tags with less than X posts
- Adding a tax_query to a WP_Query Object
- Finding WordPress Posts assigned to multiple categories
- Order or Orderby in tax_query (How to define order of terms in WP_Query)
- Query Posts by Tag and exclude
- Tax Query only returns for the first of several terms
- Get posts that do not have the same tags as current
- How to add tax_query to $args with concatenation
- How to print term name inside wp post loop
- Get posts in taxonomy randomly
- Loop posts based on permalink term
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Is it possible to add relation between meta_query and tax_query?
- WP_Query by keyword OR post tag
- How to restrict search on a certain page to only return results against custom taxonomies?
- Display posts by tag
- Creating attachments archive in tags and categories
- Function using get_posts() with tax_query not working when called from functions.php
- Get posts with no tags?
- Tax_Query using WP_Query not working
- Show multiple tax_query from 2 or more post_type in a single code
- Any quicker alternative for WP_Query “NOT IN”
- Tax Query on product_cat using NOT IN as operator does not exclude that category
- Filter products on category AND tag
- Facing problem with tax_query results
- WP Query should show No Posts when tax_query $args taxonomies don’t have associated posts
- Only show tag with the same id as the post
- WP_Query for a taxonomy value OR a custom post type meta field