Wordpress 按产品类型查询/筛选电子商务产品
我添加了新的产品类型,如 现在我只想展示一下这种产品类型。以下是我的问题:Wordpress 按产品类型查询/筛选电子商务产品,wordpress,woocommerce,Wordpress,Woocommerce,我添加了新的产品类型,如 现在我只想展示一下这种产品类型。以下是我的问题: $query_args = array('post_type' => 'product' ); $r = new WP_Query( $query_args ); if ( $r->have_posts() ) { ......... 如何仅查询此新产品类型的产品?在WooCommerce中,“post类型”是一种自定义分类法,因此您需要添加到WP\u query $query_args = array
$query_args = array('post_type' => 'product' );
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) { .........
如何仅查询此新产品类型的产品?在WooCommerce中,“post类型”是一种自定义分类法,因此您需要添加到WP\u 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'中的参数相同代码>新产品类型的类构造函数的一部分 一种更干净的方式-使用WoCommerce wc_get_产品,而不仅仅是WP_查询
$args = array(
'type' => 'custom_product_type'
);
$products = wc_get_products( $args );
工作得很好。非常感谢。我在产品数据中有自定义数据属性。如何在循环中使用它们?如何筛选具有此属性的产品?例如,我有颜色和大小数据属性。现在我如何列出红色和大型产品?你应该问自己的问题。请记住,属性实际上只是分类法,因此您需要制作一个更复杂的tax\u query
语句。我在这里问过,并尝试了很多组合,但我没有运行它,但只有您回答了我仍在研究的这个问题