[英]display two woocommerce categories on front page
I have two categories called mobile and laptop, which I want to show both at the same time on the main page.我有两个类别,称为移动设备和笔记本电脑,我想在主页上同时显示它们。 I used this code but it only shows one of the categories.我使用了这段代码,但它只显示了其中一个类别。 Thank you for your help谢谢您的帮助
<?php $products= new WP_Query(
array(
'post_type'=>'product',
'posts_per_page'=>'-1',
'product_cat' => 'mobile+laptop',
'orderby' => 'rand',
)
); ?>
You can use tax_query
.您可以使用tax_query
。 try the below code.试试下面的代码。
<?php
$products = new WP_Query(
array(
'post_type' => 'product',
'posts_per_page' => -1,
'orderby' => 'rand',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'mobile'
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'laptop'
)
),
)
);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.