我添加了一个新的产品类型,就像这里一样。
现在我想只显示该产品类型。这是我的查询:
$query_args = array('post_type' => 'product' );
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) { .........
如何仅查询此新产品类型的产品?
我添加了一个新的产品类型,就像这里一样。
现在我想只显示该产品类型。这是我的查询:
$query_args = array('post_type' => 'product' );
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) { .........
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';
部分相同。
$args = array(
'type' => 'custom_product_type'
);
$products = wc_get_products( $args );
tax_query
语句。 - helgatheviking