ACF リピーターフィールドでサブフィールドの最初の画像を表示させたい

通常のリピーターフィールド例
<?php if(have_rows('repeat_image')): ?>
<?php while(have_rows('repeat_image')): the_row(); ?>
<div class="block">
  <figure><img src="<?php the_sub_field('image'); ?>" alt=""></figure>
  <div class="title"><a href="<?php the_permalink() ?>"><?php echo get_the_title($post->ID); ?></a></div>
</div>
<?php endwhile; ?>
<?php endif; ?>

breakで中断してあげる必要がある

修正後

<?php if(have_rows('repeat_image')): ?>
<?php while(have_rows('repeat_image')): the_row(); ?>
<div class="block">
<figure><img src="<?php the_sub_field('image'); ?>" alt=""></figure>
<div class="title"><a href="<?php the_permalink() ?>"><?php echo get_the_title($post->ID); ?></a></div>
</div>
<?php break; ?>
<?php endwhile; ?>
<?php endif; ?>

Spread the love
2025.06.01(日)