这是我的代码(那么我如何从帖子中获得最低价格)
<div>
从父类别
获取子类别 <?php
$subcategories = get_categories('&child_of='.$cat.'&hide_empty');
foreach ($subcategories as $subcategory) {
?>
<div class="cat-con">
<?php
$subCatId=sprintf('%s',$subcategory->term_id); //the_content();
query_posts('cat='.$subCatId.'&order=ASC&meta_key=price&orderby=meta_value_number');
这部分代码让我获得自定义字段的价格
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 £<?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-->
答案 0 :(得分:1)
假设您将在底部(循环外部)回显$minPrice
:
while ( have_posts() ) : the_post();
/************************************************************************/
$price=$post->ID;
$price = get_post_meta($price, 'price', true);
if ( !isset( $minPrice ) || $price < $minPrice )
$minPrice = $price;
/************************************************************************/
答案 1 :(得分:0)
`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 )