【发布时间】:2014-03-27 12:03:59
【问题描述】:
我正在尝试获取 ONE 随机 行推荐,但是该行必须包含 sitewide_display 子字段的“真实”值。
我这辈子都无法让它工作,这只会给我刷新后的任何感觉。
像这样在 while 循环中使用子字段值 (sitewide_display) 的条件是否存在某种冲突?
<?php $rows = get_field('testimonials' ); // get all the rows ?>
<?php if( $rows ) : // if there are rows, continue ?>
<?php while( has_sub_field('testimonials') ) : ?>
<?php if( get_sub_field('sitewide_display')): ?>
<?php $rand_row = $rows[ array_rand( $rows ) ]; // get the first row ?>
<?php $rand_row_testimonial_name = $rand_row['testimonial_name' ]; // get the sub field value ?>
<?php echo $rand_row_testimonial_name; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
【问题讨论】:
标签: php loops wordpress advanced-custom-fields