[英]Get products from a specific brand in WooCommerce using a WP_Query
In WooCommerce, I am trying to display products from a specific brand in my home page like featured products section.在 WooCommerce 中,我试图在我的主页中显示特定品牌的产品,例如特色产品部分。 I tried the code below, but the products not belong to that brand.我尝试了下面的代码,但产品不属于该品牌。
This is what I tried:这是我尝试过的:
$args = array(
'post_type' => 'product',
'product_brand' => 'armitage',
'orderby' => 'rand',
'posts_per_page' => 4,
);
$loop = new WP_Query( $args );
Any suggestions?有什么建议么?
You should use tax_query您应该使用 tax_query
$args = array(
'post_type' => 'product',
'orderby' => 'rand',
'posts_per_page' => 4,
'tax_query' => array( array(
'taxonomy' => 'pa_brand-attr',
'field' => 'slug',
'terms' => 'armitage',
'operator' => 'IN',
) )
);
$loop = new WP_Query( $args );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.