2
我增加了新的产品类型像here查询/过滤器woocommerce产品按产品类型
现在我想只显示该产品类型。以下是我的查询:
$query_args = array('post_type' => 'product');
$r = new WP_Query($query_args);
if ($r->have_posts()) { .........
如何仅查询此新产品类型的产品?
我增加了新的产品类型像here查询/过滤器woocommerce产品按产品类型
现在我想只显示该产品类型。以下是我的查询:
$query_args = array('post_type' => 'product');
$r = new WP_Query($query_args);
if ($r->have_posts()) { .........
如何仅查询此新产品类型的产品?
在WooCommerce中,“帖子类型”是一种自定义分类法,因此您需要将taxonomy parameters添加到WP_Query
。
$query_args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'your_type',
),
),
);
凡terms
参数是一样的新产品类型的类的构造函数的$this->product_type = 'your_type';
一部分。
工作完美。谢谢! – trikutin
我有产品数据中的自定义数据属性。我如何在循环中使用它们?我如何过滤具有此属性的产品? 例如,我有颜色和大小数据属性。现在我该如何列出红色和大型产品? – trikutin
你应该问自己的问题。请记住,属性实际上只是分类法,所以您需要制作更复杂的'tax_query'语句。 – helgatheviking