Php 为数组中的每个项运行wp meta query arg

Php 为数组中的每个项运行wp meta query arg,php,wordpress,Php,Wordpress,因此,我有一个带有值列表的数组,我正试图对照一篇wp文章检查它,并找到最便宜的 到目前为止,我有这个 $sources = array("source 1", "source 2", "source 3", "source 4"); foreach($sources as $source) { $args .= array( 'post_type' => 'streaming-service-db', 'meta_query' => array(

因此,我有一个带有值列表的数组,我正试图对照一篇wp文章检查它,并找到最便宜的

到目前为止,我有这个

  $sources = array("source 1", "source 2", "source 3", "source 4");

  foreach($sources as $source) {
  $args .= array(
    'post_type' => 'streaming-service-db',
    'meta_query' => array(
        array(
            'key' => 'guidebox_source',
            'value' => $source,
            'compare' => '=',
        ),
    ),
);  
}               
$query = new WP_Query($args);               
if($query->have_posts()) : 
    while($query->have_posts()) : 
        $source_id = get_the_ID();  
        $price = get_field( 'cost' , $source_id);           
        if ( get_field( 'cost' , $source_id) ==  min($price) ){
            echo get_title($source_id)." is the cheapest at". get_field( 'cost' , $source_id);
        } 
         break; 
    endwhile;
endif;
wp_reset_query();
所以我知道这是完全错误的,不会按原样工作,但它应该能让我更好地了解我想做什么

从数组$sources开始

通过查找元键值“guidebox\u source”来查找$source\u id

使用Get_字段('cost',$source_id)获取其价格


然后比较价格,找出最低的。

您有多少种
流媒体服务db
?10、100、数百万?多达300个sourcesim正在考虑使用rsort(价格)$最低价格=$prices[0];我还没有弄明白如何在这种情况下使用它。我如何对价格进行排序,然后将价格以外的其他信息(如标题)重复出来?为什么不将问题更新到您现在的位置?