I have a simple query. Getting the posts only if it have both the taxonomies in it.
$args = array( 'post_type' => 'treatment', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'body-parts', 'field' => 'term_taxonomy_id', 'terms' => $_SESSION["body-parts"], ), array( 'taxonomy' => 'conditions', 'field' => 'term_taxonomy_id', 'terms' => $_SESSION["conditions"], ), ), 'posts_per_page' => -1, 'fields' => 'ids', ); $treatments = new WP_Query($args); $treatment_ids_array = $treatments->posts; var_dump($treatment_ids_array);
Now this array should be empty when there is no treatment (custom post type) related with both the taxonomies - instead it is showing all post ids in this array. Otherwise everything is working correctly - when there is actually a post with both the taxonomies - then only that post is showing.