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/why does ‘$query->get( ‘tax_query’ );’ return empty?

AFAIK $query->get for main query works only with public query vars, i.e. vars that can be triggered via url, but nothing prevents to directly access directly to tax_query property of query, but notice that it is an object, instance of WP_Tax_Query and the current queried taxonomy arguments are in the queries property of that object. … 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

Conditional arguments for WP_Query and tax_query depending on if $somevar has a value

You can define the args outside of the WP_Query instantiation: <?php $tax_query = array(‘relation’ => ‘AND’); if (isset($search_course_area)) { $tax_query[] = array( ‘taxonomy’ => ‘course-area’, ‘field’ => ‘id’, ‘terms’ => $search_course_area ); } if (isset($search_course_level)) { $tax_query[] = array( ‘taxonomy’ => ‘study-levels’, ‘field’ => ‘id’, ‘terms’ => $search_course_level ); } if (isset($search_course_mode)) { $tax_query[] = … Read more

Custom Taxonomy and Tax_Query

First of all, you run register_post_type on init and register_taxonomy on after_setup_theme which is called after init. This means your custom taxonomy will not be available when registering the post type. I would suggest you remove the taxonomies keyword from the register_post_type arguments array, and just register the taxonomy manually afterwards. In your example code … Read more