woocommerce所有产品尺寸列表

huangapple go评论74阅读模式
英文:

woocommerce list of all products sizes

问题

我需要获取所有产品的尺寸(宽度和高度)。我使用以下代码:

$allProducts = wc_get_products(array(
	'status' => 'publish',
));
$allWidthArr = array();
$allHeightArr = array();
foreach ( $allProducts as $product ) {
	$allWidthArr[] = $product->get_width();
	$allHeightArr[] = $product->get_height();
}

我可以在不循环所有产品的情况下获取这些数据吗?

英文:

I need to get of all products sizes(width and height). I use this code:


$allProducts = wc_get_products(array(
	'status' => 'publish',
));
$allWidthArr = array();
$allHeightArr = array();
foreach ( $allProducts as $product ) {
	$allWidthArr[] = $product->get_width();
	$allHeightArr[] = $product->get_height();
}

Can I get this data without loop all products?

答案1

得分: 2

我建议使用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);
英文:

I would recommend using a MYSQL Query.

Try the following lines of code,

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);

huangapple
  • 本文由 发表于 2020年1月7日 00:03:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定