【发布时间】:2017-04-01 23:02:07
【问题描述】:
我正在尝试使用 product_cat 获取所有产品 ID,这是我的代码
function get_products_from_category_by_ID( $category ) {
$products_IDs = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $category,
)
),
) );
return $products_IDs;
}
var_dump( get_products_from_category_by_ID( 196 ) );
但是获取 WP_Query 对象而不是产品的 id,请告诉我可能是什么原因?
参考:- WooCommerce: function that returns all product ID's in a particular category
【问题讨论】:
标签: php wordpress woocommerce