检查ACF中继器中的行值是否匹配

问题描述 投票:1回答:1

我有几行ACF中继器。

我需要检查所有$distance值是否都超过100。

<?php if( have_rows('store') ): ?>
  <?php while( have_rows('store') ): the_row();

    $distance = get_sub_field('distance'); ?>

    <?php echo $distance; ?>

  <?php endwhile; ?>
<?php endif; ?>
php advanced-custom-fields
1个回答
0
投票

我通过制作一个数组来解决此问题,然后使用min进行检查。

<?php if( have_rows('store') ): $distances = array(); ?>
  <?php while( have_rows('store') ): the_row();

    $distance = get_sub_field('distance'); ?>
    $distances[] = $distance;

    <?php if (min($distances) >= 100) { echo 'all over 100'; } ?>

  <?php endwhile; ?>
<?php endif; ?> 
© www.soinside.com 2019 - 2024. All rights reserved.