问题描述
在 WooCommerce 中,我尝试从多个类别中获取 10 种产品,这是我的代码:
$args = array(
'post_type' => 'product','posts_per_page' => 10,'product_cat' => 'ring,watch,earring'
)
);
$loop = new WP_Query( $args );
我只从第一类中获得 10 种产品。
有没有办法从多个类别中获得 10 个混合产品?
解决方法
更新
您的代码有点过时,请尝试使用以下方法从特定产品类别术语中查询产品使用参数“orderby”设置为“rand” (随机排序) 使它们混淆:
$loop = new WP_Query( array(
'post_type' => 'product','posts_per_page' => 10,'post_status' => 'publish','orderby' => 'rand','tax_query' => array( array(
'taxonomy' => 'product_cat','field' => 'slug','terms' => array('ring','watch','earring'),) ),) );
经过测试和工作。