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

$wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies

Do a tax-query and then count the result. No need for a custom query with dozens of JOINS. $posts = new WP_Query( array( ‘post_type’ => ‘MYPOSTTYPE’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘TAX_1’, ‘field’ => ‘slug’, ‘terms’ => array( ‘TERM_TAX_1’ ), ‘operator’ => ‘IN’ ), array( // etc. ) ), ‘post_status’ => ‘publish’ ); prinft( … 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’ ) ) );

tax_query: Order by slug?

If I understand your scenario, your events are in the right order but your semesters are not. If you change line 4 $terms = get_terms(‘semesters’); to $terms = get_terms(‘semesters’, array( ‘orderby’ => ‘slug’ ) ); that should put the semesters in the order you’re looking for. ‘order’ defaults to ASC, which is what you need … Read more

pre_get_posts Remove tax_query Completely

This fixed it! 🙂 Hat-tip gmazzap for the useful info: Obliterate the main query and replace it function wpse_286813_omit_all( $query_vars ){ // triggered also in admin pages if ( is_admin() ) return $query_vars; if( !empty($query_vars[‘taxo’]) && $query_vars[‘taxo’] === ‘all’ ){ $query_vars[‘taxo’]=”; } return $query_vars; } add_filter( ‘request’, ‘wpse_286813_omit_all’ );

Custom taxonomy query not working with switch_to_blog

I find the solution: Tax_query not working on multisite (I dont say, that I work with switch_to_blog, because everything is works fine with this function… everything, including postmeta queries, category__not_in, etc., but EXCEPT: tax_query) So, “you have to register that custom taxonomy in both blogs”. <– so the problem originate from the different themes, when … Read more

Get list of terms that have posts in another term

Try replacing ‘operator’ => ‘AND’ with ‘relation’=>’AND’ Updated Code Snippet: $current_color = get_queried_object_id(); $query = new WP_Query( array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘tax_query’ => array( ‘relation’ => ‘AND’ array( ‘taxonomy’ => ‘pa_color’, ‘field’ => ‘term_id’, ‘terms’ => $current_color, ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ … Read more