在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'),
) ),
) );
经过测试和工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句