It’s actually pretty simple: You’ll want to use an OR
relation, and use the NOT EXISTS
operator for selecting posts that are not assigned to any terms in the specified taxonomy.
$tax_query[] = array(
'relation' => 'OR',
array(
'taxonomy' => 'location',
'field' => 'name',
'terms' => $location,
),
array(
'taxonomy' => 'location',
'operator' => 'NOT EXISTS',
),
);
Related Posts:
- Show posts without term
- List taxonomy terms plus their latest post ordered by post date
- Get array of current post term ID’s
- Function get_queried_object() return NULL in custom taxonomy
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- List custom taxonomy terms sharing posts with a term from a second custom taxonomy
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- Filter Custom Taxonomy Posts
- How to add custom meta to ‘pre_get_terms’?
- get term id from term name
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- How to print term name inside wp post loop
- Check if a post has term inside loop
- display ACF repater field in archive page
- How to define a custom hierarchy for terms?
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- WordPress tax_query “and” operator not functioning as desired
- Custom taxonomy query broken after upgrade to 4.4
- query multiple taxonomies
- Display posts the match taxonomy term linked from wp_list_categoies?
- Why is my WP_Query not working when tax_query terms are an array?
- Counting number of posts with Category B in Category A
- Custom archive page based on array of categories and tags
- Sort the main query in subcategories/terms?
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Order terms inside a select dropdown
- tax_query shows no results if nothing is selected
- How to Modify Taxonomy Archive Page with Search Parameter?
- How to add terms to my tax_query based off of the current post
- Setup of taxonomy term template pages
- Change default ordering of taxonomy terms – pre_get_terms
- How to do a query on custom taxonomies that is uncategorised?
- WP_Query, tax_query and term_meta: How to?
- Order taxonomy terms in alphabetical order
- Empty tax_query array returns an empty array
- Query Custom Post Type Order By Taxonomy Field
- Query post from all category with same tag on 1 pages
- Query with custom taxonomy not working
- Getting Taxonomy inside WP_Query Loop
- Order posts by taxonomy count
- showing all search result in one template
- How to Filter Posts by Custom Fields?
- Show posts from a custom taxonomy on a page
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How do I exclude the lowest level terms in a taxonomy?
- Query with relation and one without relation using multiple taxonomies?
- How to display an other custom post type in a different custom post type’s archive?
- Display custom tags on pages that have a specific page parent
- wp_query args adding muitiple tax_querys
- find posts that don’t have a custom taxonomy
- Custom taxonomy.php not working
- WP_Query for a taxonomy with different taxonomy types
- get all posts associated with a custom taxonomy
- How to set an alternate posts_per_page value for default queries in different templates
- Get posts from multiple tax terms
- How to Order a list of taxonomies? orderby?
- One WP_Query that always shows 1 post from category X and 1 post from “not in category X”?
- Using WP_Query for categories instead of get_terms
- Grabbing taxonomy terms and inserting them into an array
- How to get posts by category and by choosing a taxonomy term?
- How to restrict search on a certain page to only return results against custom taxonomies?
- Deleting terms from the WordPress wp terms table
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- How to make a post with certain taxonomy term display first before other post with only one query?
- wp-query and wp_get_post_terms on custom taxonomy archive page
- Why is my pagination /page/2 taking me to index.php?
- How can I order a post query’s results based on the number of matching taxonomy terms?
- Only show tag with the same id as the post
- Filter for each loop when WP_Query has no posts to show
- WP Query by 4 different taxonomies
- How do I stop the same post showing multiple times in a archive?
- Related categories order posts by category
- WordPress – Form does not filter the results of taxonomies
- WP Query for all events prior to current date
- How to get taxonomy image attached to a Post Type WordPress
- list all post who have mutual taxonomy as current taxonomy!
- Show one post of each custom taxonomy
- Displaying posts from sub taxonomies only
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- taxquery taxonomy get terms
- get term objects and post objects in query
- How to show terms from another taxonomy
- My entry results are not consistently alphabetized
- I cannot get tax_query in get_posts() to work with custom taxonomy
- Display all Custom taxonomy terms and their relevant custom posts
- How can I get all the posts that are related with a specific taxonomy term?
- How to combine nested tax_query logic with other nested query logic?
- tax_query not working for taxonomy slug
- Custom query for tag and custom tag from 2 post type
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- WP_Query to show post from a category OR custom field – Not 100% answered
- How to pass taxonomy terms to WP_Query along with $args?
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- How to get several fields from wp_query?
- Page displaying 1st post from a range of custom tax?
- WordPress WP_Query Array Custom search via taxonomies
- Order posts with custom taxonomy array
- How to Get The Taxonomy Term in Custom Post Type Loop Inside a Wp Query
- I need to get all categories from a WP_Query
- Custom Taxonomy in custom REST API search