如何通过ID获得最低和最高的产品价格?

发布于 2025-01-25 18:21:05 字数 1017 浏览 2 评论 0原文

大家好,假设我有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2025-02-01 18:21:06

您可以添加order_by参数,并将属性的名称添加为值(如果我没记错的话,“价格”):

    'orderby'           => 'price',

这是您可以应用于查询的其他参数的列表

You can add the order_by parameter, and the name of the property as the value ("price", if I'm not mistaken):

    'orderby'           => 'price',

Here's a list of the other parameters you can apply to your query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文