按产品类型查询/过滤woocommerce产品 [英] Query / Filter woocommerce products by product type
本文介绍了按产品类型查询/过滤woocommerce产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我只想展示该产品类型.这是我的查询:
Now I want to show just that product type. Here is the my query:
$query_args = array('post_type' => 'product' );
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) { .........
如何只查询这种新产品类型的产品?
How can I query only products of this new product type?
推荐答案
在 WooCommerce 中,post type"是自定义分类法,因此需要添加 分类参数 到 WP_Query
.
In WooCommerce, "post type" is a custom taxonomy, so you need to add taxonomy parameters to 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';
部分相同.
Where the terms
argument is the same as in the $this->product_type = 'your_type';
part of your new product type's class constructor.
这篇关于按产品类型查询/过滤woocommerce产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文