我需要获取所有产品尺寸(宽度和高度)。我使用这段代码:$allProducts = wc_get_products(array( 'status' => 'publish',));$allWidthArr = array();$allHeightArr = array();foreach ( $allProducts as $product ) { $allWidthArr[] = $product->get_width(); $allHeightArr[] = $product->get_height();}我可以在不循环所有产品的情况下获取这些数据吗?
1 回答

慕妹3146593
TA贡献1820条经验 获得超9个赞
我建议使用 MYSQL 查询。
尝试以下代码行,
global $wpdb;
$list_of_heights = $wpdb->get_results('SELECT post_meta.meta_value FROM '.$wpdb->prefix.'posts posts INNER JOIN '.$wpdb->prefix.'postmeta post_meta
ON post_meta.post_id=posts.ID where post_type="product" and post_meta.meta_key="_height"',ARRAY_N);
$list_of_widths = $wpdb->get_results('SELECT post_meta.meta_value FROM '.$wpdb->prefix.'posts posts INNER JOIN '.$wpdb->prefix.'postmeta post_meta
ON post_meta.post_id=posts.ID where post_type="product" and post_meta.meta_key="_width"',ARRAY_N);
- 1 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消