WP_Query tax_query problem

Found problem. I replaced: $posts = $query->get_posts(); with: $posts = array(); if ($query->have_posts()){ while ($query->have_posts()){ $query->next_post(); array_push($posts, $query->post); } } And everything is working now.

Dynamically tax_query terms

If $taxonomy_category is already an array, then: ‘terms’ => array($taxonomy_category) should just be: ‘terms’ => $taxonomy_category where $taxonomy_category is equal to whatever was submitted from your form as $_POST[‘taxonomy_category’] or $_GET[‘taxonomy_category’]

WP_Query tax_query on ACF post_object

Update 1 As @Florian pointed out, we do not need to use the wp_list_pluck function, we could simply add the ‘fields’ => ‘ids’ to the WP_Query to retrieve the list of ids: $producers = new WP_Query( array( ‘fields’ => ‘ids’, ‘post_type’ => ‘producers’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘region’, ‘field’ => … Read more

get complex results set according to category structure

Thinking aloud here… $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( 202, 203 ), ‘include_children’ => 1, ), array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( 100 ), ‘include_children’ => false, ) ), ), ); … Read more

WP_Tax_Query with post_tag not working

I did get the thing working, though I’m not entirely sure how. I made two changes: Removed the “convert array to Tax_Query object” step (which I only put in because using an array wasn’t working before) Added a direct assignment of the array to the $query object (rather than just using the set() method). My … Read more

tax_query shows no results if nothing is selected

So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET[‘suburbs’] ) ) { $suburbs = $_GET[‘suburbs’]; } // States if( !empty( $_GET[‘states’] ) ) { $states = $_GET[‘states’]; } // Query arguments. $args = array( ‘post_type’ => ‘properties’, ‘posts_per_page’ => 10, ); $taxquery = array(); // if … Read more

tax_query: What to pass when I want to have all terms?

Simply omit (or not add) tax_query part of arguments. $args = array( ‘post_type’ => ‘wr_event’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => $order, ‘meta_value’ => $yesterday, ‘meta_compare’ => $compare, ); if ( ! is_null($cat) ) $args[‘tax_query’] =array( array( ‘taxonomy’ => ‘event_type’, ‘field’ => ‘slug’, ‘terms’ => $cat, ‘operator’ => ‘IN’ ), … Read more

How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero

You can do this with just get_terms – this allows you to fetch all (or some) of the terms from one (or more) taxonomies. By default it excludes ’empty’ terms, so you’ll need to set the arguments appropriately. //Array of taxonomies to get terms for $taxonomies = array(‘category’,’post_tags’,’my-tax’); //Set arguments – don’t ‘hide’ empty terms. … Read more