我正在尝试获取一个随机的推荐行,但是该行必须包含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; ?>