Tax query with `AND` operator does not work with WooCommerce category


In WooCommerce categories, I have Cat 1 (slug is cat-1) and Cat 2 (slug is cat-2). I added many products which belong to both categories. But when i want to query those products, no products found:

$q = new WP_Query([
    'post_type' => 'product',
    'post_status' => 'publish',
    'tax_query' => [
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => ['cat-1', 'cat-2'],
            'operator' => 'AND'

var_dump($q->posts); // empty array

Am I missing something?

The weird thing is when i tested the query with the default post post type and the category taxonomy, everything worked fine.

, MinhTri 4 years 2020-02-27T08:38:28-05:00 0 Answers 70 views 0

Leave an answer