WP_Query Woocommerce products that belong in distinct multiple categories only tax_query

后端 未结 4 604
猫巷女王i
猫巷女王i 2021-01-31 21:04

I\'m using WP_Query for Woocommerce products in attempt to query products in a particular category. This is the syntax that worked for me -

$args =         


        
4条回答
  •  猫巷女王i
    2021-01-31 21:33

    From the WordPress codex on WP_Query for Category Parameters:

    equivalent of OR

    $args = array( 'product_cat' => 'category-slug1,category-slug2' ) );
    

    equivalent of AND

    $args = array( 'product_cat' => 'category-slug1+category-slug2' );
    

    e.g.

    $query = new WP_Query( $args );
    

提交回复
热议问题