tax_query will produce nothing

Looking at the WP_Query documentation on tax_queries we can see it accepts a nested array as a parameter. Compare that to the provided code: ‘tax_query’ => array( ‘taxonomy’ => ‘news_category’, ‘field’ => ‘term_id’, ‘terms’ => 82, ), Should look like: ‘tax_query’ => [ [ ‘taxonomy’ => ‘news_category’, ‘field’ => ‘term_id’, ‘terms’ => 82, ] ],

How to set `tax_query` with `query->set()`

Main problem with your code is that tax_query should be an array of queries, and not a single query. $tax_query = array( array( ‘taxonomy’ => ‘filter’, ‘terms’ => array(30140, 30020, 30008, 29998, 29991, 21458,20197,11986,6614), ‘field’ => ‘term_id’, ‘operator’ => ‘NOT IN’ ) ); $query->set( ‘tax_query’, $tax_query );

simple tax_query intersection

As jdm2112 and SallyCJ said in the comments, the query lacks of ‘field’ => ‘slug’. So: ‘tax_query’ => [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘link-category’, ‘terms’ => $link, ‘field’ => ‘slug’ ], [ ‘taxonomy’ => ‘despacho’, ‘terms’ => $despacho, ‘field’ => ‘slug’ ], ],

OR for a single taxonomy in a tax_query

So in the comments you said: We’re in the middle of an address system migration and this query needs to return objects where one of these matches. Either the old system (county field) is set to an id, or the address value has a match to the search word If you look at the documentation, … Read more

in_category() and tax_query with custom post type

Instead of in_category try has_term – http://codex.wordpress.org/Function_Reference/has_term This should work (I’ve tested it in a simpler form on my localhost): <?php get_header(); ?> <div id=”body”> <div class=”fix”> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if ( has_term(‘natige’, ‘products_brand’)) :?> <div class=”col-2 nati-col”> <div class=”col-left”> <div class=”nav”> <a href=”https://wordpress.stackexchange.com/questions/137042/<?php if (ICL_LANGUAGE_CODE ==”ru’){ echo … Read more

using multiple terms in tax_query

You’re mixing up arrays. In your “my implode”, $checkedBundeslaenderList varies between a string and an array, depending on the number of items. And then in your query args, you nest it in an array: ‘terms’ => array( $checkedBundeslaenderList ), So what you could end up with is either: array( array( 1 ) ); …or: array( … Read more

How to write a Tax Query that matches all terms in an array?

I believe changing your operator to ‘AND’ like below will work: $selectedOptions = array(‘test-attribute’, ‘test3’); $args=array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘pa_filterable-attribute’, ‘terms’ => $selectedOptions, ‘field’ => ‘slug’, ‘operator’ => ‘AND’ ) ) );

Multiple, nested tax_query relation

The cat-parameter is not overwritten by tax_query. Instead, it is added to tax_query. Thus, using ‘cat’ => -5, the following array is appended to tax_query: ( [taxonomy] => category [terms] => Array ( [0] => 5 ) [include_children] => 1 [field] => term_id [operator] => NOT IN ) The resulting taxonomy query is built up … Read more

tech