【问题标题】:wordpress return post_meta values lowest firstwordpress 返回 post_meta 值最低的第一
【发布时间】:2013-08-05 12:32:58
【问题描述】:

我有以下查询,它会遍历 meta_value 为“1284”的帖子

global $wpdb;

$table =  $wpdb->prefix . 'postmeta';
$theid = get_the_id();
$todayVisits = $wpdb->get_results("SELECT * FROM $table WHERE meta_value = '$theid' LIMIT 1 ");

foreach ( $todayVisits as $post ){

echo get_woocommerce_currency_symbol().get_post_meta( $post->post_id, '_wholesale_price', true );

}

在 foreach 循环中,我得到元键“_wholesale_price”

如何只显示最低的“_wholesale_price”?

我尝试过像这样使用 php 函数“min”:

min(array(get_post_meta( $post->post_id, '_wholesale_price', true ).',')); 

但我猜那不是正确的方法,因为它不起作用。

编辑:

我尝试了以下方法,但这会返回最大值:

$price = min(get_post_meta( $post->post_id, '_wholesale_price', false ));

【问题讨论】:

    标签: php wordpress


    【解决方案1】:
    $prices = get_post_meta($post->post_id, '_wholesale_price'); // get all prices
    rsort($prices); // sort in descending order
    
    $min_price = $prices[0]; // lowest
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2022-07-13
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      相关资源
      最近更新 更多