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
- How to add taxonomy filter on the query fly?
- query multiple taxonomies
- Display posts the match taxonomy term linked from wp_list_categoies?
- Query two taxonomies via URL or link?
- Why is my WP_Query not working when tax_query terms are an array?
- Get list of posts which have at least one term from a custom taxonomy with WP_Query
- Counting number of posts with Category B in Category A
- Custom archive page based on array of categories and tags
- Select posts wich has no relationship in custom taxonomy
- Sort the main query in subcategories/terms?
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- Get random terms
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- Order terms inside a select dropdown
- Filter and list posts of a custom taxonomy
- WP_Query use for a filter with multiple Taxonomies and Terms
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- 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
- Display link to taxonomy archive only if it has posts with certain custom field values
- 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
- Pass array of taxonomy terms to wp_query
- Query Custom Post Type Order By Taxonomy Field
- Get list of terms that have posts in another term
- Formulate a url to show posts with both taxonomy terms
- Query post from all category with same tag on 1 pages
- Query with custom taxonomy not working
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- Order by slug in get_terms with multiple taxonomies
- WordPress Related Post by tags in Single.php
- Getting Taxonomy inside WP_Query Loop
- Order posts by taxonomy count
- showing all search result in one template
- Filtering WP_Query Dynamically on the Front-End
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Query custom post type by custom taxonomy (category slug)
- How to Filter Posts by Custom Fields?
- Get authors by term id or slug
- Show posts from a custom taxonomy on a page
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- WP_Query ignoring tax_query when is_singular
- How do I exclude the lowest level terms in a taxonomy?
- wp_query for multiple cities (multiple values in a metabox)
- How to order posts by title after they have already been sorted by category
- 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?
- Search form not working with custom query?
- Post loop for all taxonomy terms
- 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
- Taxonomy order exception for specific term
- Custom taxonomy.php not working
- WP_Query args to show posts from specific custom taxonomy
- 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
- Using custom taxonomies in a query
- Get posts from multiple tax terms
- How to Order a list of taxonomies? orderby?
- get_the_terms – but only show 4 Posts
- Count posts per taxonomy else change taxonomy if less than x number
- Tax Query only returns for the first of several terms
- Can’t fetch Custom Post Type Data through Custom Query
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- 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?
- Query Taxonomy By Page Title
- Custom Taxonomy Breaks Pages
- Wp_query…a type of term a different div
- Deleting terms from the WordPress wp terms table
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- get_the_terms has strange result since version 6.0