如何通过ID获得最低和最高的产品价格?
大家好,假设我有10种产品
如何获得最低价格和最高价格?
我有拥有所有产品ID的$ products_ids
$products_price_desc = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'orderby' => 'price',
'order' => 'DESC'
'fields' => 'ids',
));
$products_price_asc = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'orderby' => 'price',
'order' => 'ASC'
'fields' => 'ids',
));
,现在如何获得最低和最大价格值?并在这里使用
$ max_price = $ products_price_desc;
$ min_price = $ products_price_asc;
<input type="range" min="<?php echo $min_price ?>"
max="<?php echo $max_price ?>">
hey guys let's say I have 10 products
how can I get the lowest price of them and the highest price of them too?
I have $products_ids which has all the products id's
$products_price_desc = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'orderby' => 'price',
'order' => 'DESC'
'fields' => 'ids',
));
$products_price_asc = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'orderby' => 'price',
'order' => 'ASC'
'fields' => 'ids',
));
And now How I can get the min and max price value of them? and to use here
$max_price= $products_price_desc;
$min_price= $products_price_asc;
<input type="range" min="<?php echo $min_price ?>"
max="<?php echo $max_price ?>">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加order_by参数,并将属性的名称添加为值(如果我没记错的话,“价格”):
这是您可以应用于查询的其他参数的列表。
You can add the order_by parameter, and the name of the property as the value ("price", if I'm not mistaken):
Here's a list of the other parameters you can apply to your query.