我使用高级自定义字段获取属性列表,如下所示:-
<?php
$args = array(
\'posts_per_page\'=> -1,
\'post_type\' => \'properties\',
\'meta_key\' => \'development\',
\'meta_value\' => $development_id
);
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-md-4">
<?php the_title(); ?>
<?php the_field(\'price\'); ?>
Plot <?php the_field(\'plot_no\'); ?>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
以下内容:;
<?php the_field(\'price\'); ?>‘
返回值:-
325000 489950 329000 325000 294995 199950 294995 252950 325000 257950 197950 325000
我需要的是得到变量的最低值和最高值,你知道我该怎么做吗?
SO网友:darrinb
如果不知道是返回单个值、数组还是由空格分隔的值字符串,我建议如下:
<?php
$args = array(
\'posts_per_page\'=> -1,
\'post_type\' => \'properties\',
\'meta_key\' => \'development\',
\'meta_value\' => $development_id
);
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $min_price = $max_price = \'\'; ?>
<div class="col-md-4">
<?php the_title(); ?>
<?php
$price = get_the_field(\'price\');
if( $price ) {
// if it\'s an array already:
$min_price = min($price);
$max_price = max($price);
// if it\'s not an array already:
$prices = explode(\' \', $price);
$min_price = min($prices);
$max_price = max($prices);
}
?>
<?php the_field(\'price\'); ?>
Plot <?php the_field(\'plot_no\'); ?>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>