Wordpress 如何从贴子的自定义字段中获取最低价格

Wordpress 如何从贴子的自定义字段中获取最低价格,wordpress,custom-fields,Wordpress,Custom Fields,这是我的代码(那么如何从帖子中获得最低价格) 它正在从父类别中获取子类别 <?php $subcategories = get_categories('&child_of='.$cat.'&hide_empty'); foreach ($subcategories as $subcategory) { ?> “alt=”“/> 价格从英镑开始; 假设您在底部(循环外部)回显$minPrice: while(hav

这是我的代码(那么如何从帖子中获得最低价格)


它正在从父类别中获取子类别

    <?php 
    $subcategories = get_categories('&child_of='.$cat.'&hide_empty');
    foreach ($subcategories as $subcategory) {
    ?>





“alt=”“/>

价格从英镑开始;

假设您在底部(循环外部)回显
$minPrice

while(have_posts()):the_post();
/************************************************************************/
$price=$post->ID;
$price=get\u post\u meta($price,'price',true);
如果(!isset($minPrice)|$price<$minPrice)
$minPrice=$price;
/************************************************************************/

假设您在底部(循环外部)回显
$minPrice

while(have_posts()):the_post();
/************************************************************************/
$price=$post->ID;
$price=get\u post\u meta($price,'price',true);
如果(!isset($minPrice)|$price<$minPrice)
$minPrice=$price;
/************************************************************************/
/************************/

It is getting me value array
Array ( [0] => 2500 )
Array ( [0] => 3500 )
/************************/

It is getting me value array
Array ( [0] => 2500 )
Array ( [0] => 3500 )

while(have_posts()):the_post();$price1=get_post\u meta($post->ID,“price”,false);echo$minPrice=min($price1);endwhile;
/************************************************/这是因为您将'false'作为第三个参数:并使用min()在只有1个值的数组中是无用的:(除非“price”元键中有多个值)。
while(have_posts()):the_post();$price1=get_post_meta($post->ID,“price”,false);echo$minPrice=min($price1);endwhile;
/***************************************/它是get-me-value数组([0]=>2500)数组([0]=>3500)这是因为您将“false”作为第三个参数:并且在只有1个值的数组中使用min()是无用的:(除非“price”元键中有多个值)。
while ( have_posts() ) : the_post();

      /************************************************************************/

      $price=$post->ID; 
      $price = get_post_meta($price, 'price', true);
      if ($price <= 3500) {
      $minPrice=$price;
      /************************************************************************/
          ?>
     <div class="cat-img">
     <?php $postID=$post->ID; $image = wp_get_attachment_image_src (get_post_thumbnail_id( $pageID ),'medium', true) ; ?>
     <img width="445" height="209" src="<?php echo $image[0]; ?>" alt="" />
     </div>
                  <div class="clear"></div>
                  <div class="cat-heading">
                      <?php echo sprintf('<a href="%s">%s</a>',get_category_link($subcategory->term_id), apply_filters('get_term', $subcategory->name));?></a>
                  </div>
                  <div class="clear"></div>
                  <div class="cat-con-text">
                      <p><?php the_content(); ?><p>
                  </div>
                  <div class="clear"></div>

                  <div>
                      <div class="floatright">
                          <a href="<?php echo sprintf('%s',get_category_link($subcategory->term_id)); ?>"><img src="<?php bloginfo( 'template_directory' );?>/images/btn-view.png" alt="" /></a>
                      </div>
                      <div class="cat-price">Price Start From &pound;<?php echo $minPrice?></div>
                      <div class="clear"></div>
                  </div>
                      <?php    
              } // end if $price
              endwhile; ?>
        </div>
        <?php } //end foreach; ?>
        <div class="clear"></div>
    </div>
    <!--End Category-->
while ( have_posts() ) : the_post();

/************************************************************************/

$price=$post->ID; 
$price = get_post_meta($price, 'price', true);

if ( !isset( $minPrice ) || $price < $minPrice )
    $minPrice = $price;

/************************************************************************/
`while ( have_posts() ) : the_post();
$price1 = get_post_meta($post->ID, "price", false);
echo $minPrice = min($price1);
endwhile;
`
It is getting me value array
Array ( [0] => 2500 )
Array ( [0] => 3500 )