我添加了新的产品类型,例如here https://wordpress.stackexchange.com/a/120220/66786
现在我想展示该产品类型。这是我的查询:
$query_args = array('post_type' => 'product' );
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) { .........
如何只查询该新产品类型的产品?
在 WooCommerce 中,“帖子类型”是自定义分类法,因此您需要添加分类参数 http://codex.wordpress.org/Class_Reference/WP_Query#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';
新产品类型的类构造函数的一部分。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)