![](/img/trans.png)
[英]How to get all products from current WooCommerce product category?
[英]Get all products which have both product category
我需要同時具有這兩種類別的所有產品。 我在下面使用查詢:
$args = array(
'post_type' => array('product', 'product_variation'),
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'shop', 'cat1' ),
'operator' => 'AND',
)
)
);
如果cat1類別不包含cat1-1,cat1-2等任何子類別,則它可以正常工作。但是當我在cat1的后端創建子類別時,結果將為零。
如果cat1具有子類別,則查詢相同,只是沒有結果。
謝謝
在參數中添加包含子項。
確保您的產品同時具有這兩個類別。
如果要按多個類別進行過濾,則運算符可以為“ IN”,而不是“ AND”。
$args = array(
'post_type' => array('product', 'product_variation'),
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'include_children' => true,
'field' => 'slug',
'terms' => array( 'shop', 'cat1' ),
'operator' => 'AND',
)
)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.