In this example, my ACF group is named services
and the repeater sub-field is named services_list
.
Why would I use an ACF group?
The group feature in Advanced Custom Fields is useful when organizing both the dashboard user interface as well as the data. In my markup below, I added minimal HTML which hopefully helps a bit with clarity.
<?php
// Stop if there's nothing to display.
if ( ! have_rows( 'services' ) ) {
return false;
}
if ( have_rows( 'services' ) ) : ?>
<?php while ( have_rows( 'services' ) ) : the_row();
// Services Sub Repeater.
if ( have_rows( 'services_list' ) ) : ?>
<ul class="services">
<?php
while ( have_rows( 'services_list' ) ) : the_row();
$image = get_sub_field( 'icon' );
$title = get_sub_field( 'service_title' );
$content = get_sub_field( 'service_content' );
?>
<li class="services-single">
<img src="<?php echo esc_url( $image['sizes']['thumbnail'] ); ?>" alt="<?php echo esc_html( $image['alt'] ); ?>"?>
<?php echo esc_html( $title ); ?>
<?php echo esc_html( $content ); ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Just fyi, you should take out the $service = get_field(‘service’); because it causes in error when initially starting the if/while loop. This will work when that is taken out.
Hi Collin, that’s weird! It doesn’t break anything on my end. But you’re right, you can get rid of it without any effect. I’ll edit that line out in case it is causing errors for people.
This was very helpful. Thank you!
You’re welcome! Glad you found it of use.
I had a nested repeater within a group within an options page, haha. Custom field Inception! This helped me out today, thank you.
Oh my goodness! That’s next level 😆. Glad this was useful in your nesting inception journey.
Hi Matt,
Same problem on my end, but I’m kind of lost on how to show the content of the nested repeater. How did you proceed?
Could you share your code?
Thanks!
This is a great help – thanks!
You’re welcome!
This pointed me in the right direction. Gracias!
Awesome, you’re welcome!
thanks for sharing this code
You’re welcome!
As everyone has said above, this has truly helped me. Thank you for sharing, this type of clarity is rarely shown so simplistically. Sweet sweet working group/repeater loops.
Thanks for commenting! I’m glad it was of use to people other than myself 🙂
This was a great help, thank you!
Thanks for sharing this bit of knowledge!