advanced custom fields repeaterでリピーターの行の最大値を取得する方法 Count total number of repeater rows
これで行の最大値を取得できます。
<?php get_sub_field('grid_block'); ?>
このように変数に代入して使えます。
<?php if (have_rows('food_free_repeater')): ?> <?php while (have_rows('food_free_repeater')): the_row(); ?> <p class="circle01"><?php the_sub_field('food_free_ttl'); ?></p> <div><?php the_sub_field('food_free_content'); ?></div> <?php $max_counter = count(get_sub_field('food_child_free_repeater')); ?> <div class="flex_block"> <?php if (have_rows('food_child_free_repeater')): ?> <?php $count = 1; ?> <?php while (have_rows('food_child_free_repeater')): the_row(); ?> <div class="flex_box <?php if ($count == $max_counter && $max_counter%2 !== 0 ): ?> box100 <?php endif; ?> "> <p class="flex_box_ttl"><?php the_sub_field('food_child_ttl'); ?></p> <div> <?php the_sub_field('food_child_txt'); ?> </div> </div> <?php $count++; ?> <?php endwhile; ?> <?php endif; ?> </div> <?php endwhile; ?> <?php endif; ?>
参考サイト
Count total number of repeater rows