on-internet
← Community

wc_get_products(): include products in specific categories and exclude another

Stack Overflow ·

If I run this query, I get all the products I want: $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'category' => array( 'wordpress', 'plugin' ), ); $products = wc_get_products( $args ); However, the following query returns just 1 product (but it should return all). Why doesn't it return all products like the query above? $args = array( 'post_type' => array( 'product' ), 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', // Condition 1: Product MUST belong to BOTH of these categories array( 'taxonomy' => '

Comments

Sign in or sign up to comment and upvote.

No comments yet.