The Operator “NOT IN” Does Not Work In tax_query

I suspect you need an array for the terms – although I’m not sure why it would work with “IN” and not with “NOT IN”… But I’d try this: function menta_pre_get_posts( $query ) { if ( !is_admin() && $query->is_search() && $query->is_main_query() ) { $term = get_term_by(‘slug’, get_query_var(‘s’), ‘product_tag’); if ( $term && !is_wp_error( $term ) … Read more

WordPress tax query use operator LIKE

The only option you have is to write your own SQL into the posts_clauses filter, where you get an array of the JOIN, WHERE, ORDER, etc. clauses that you can alter, add to, remove, etc. One MAJOR MAJOR note on this, is ALWAYS use the global $wpdb‘s prepare function, which will sanitize all your lovely … Read more

Tax_query terms ID’s using variable

It looks like you are making an array with a single string inside. Check if making $tax into an array before passing it will work: $tax = array( 19, 18, 214, 226, 20 ); $query_args = array ( ‘post_type’ => ‘works’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘materials’, ‘field’ => ‘term_id’, ‘terms’ => $tax, ) … Read more

pre_get_posts with tax_query causes empty result

You use tax_query incorrectly. Take a look at Codex Page tax_query should be an array which can contain: relation – it should be string (AND/OR) taxonomy term – array with defined taxonomy, field, terms, and so on. In your code your setting tax_query to: $taxquery = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ … Read more

When tax_query used, results disappear (0 =1 produced)

tax_query takes an array of arrays. You have an array of arrays of arrays. var_dump($tax_queries); and will get this: array(1) { [0]=> array(1) { [0]=> array(3) { [“taxonomy”]=> string(15) “difficulty_mode” [“terms”]=> NULL [“field”]=> string(4) “slug” } } } Try it without the square brackets. That is turn this: $tax_queries[] = array( array ( ‘taxonomy’ => … Read more