Rendering Structured Content with ACF Repeater Fields

The Repeater field is perhaps the most versatile tool in the Advanced Custom Fields (ACF) arsenal, allowing site editors to add an infinite number of rows for things like team members, price lists, or gallery items. For developers, the challenge lies in efficiently looping through this data on the front-end. This tutorial simplifies the process using the standard `while(have_rows())` loop. You'll learn how to cleanly extract sub-field data and wrap it in HTML, turning complex backend data into a beautiful, structured presentation for your visitors.

How to Loop Through ACF Repeater Fields in WordPress

ACF ACF Option Page ACF Tutorials Advanced Guides Code Snippets PHP PHP Debugging PHP Development PHP Snippets Theme Customization Theme Development Tutorials Wordpress WordPress Code Snippets WordPress Development WordPress Functions WordPress How-To WordPress Snippets WordPress Theme Development WordPress Tips WordPress Tutorials WP Hooks

How to Loop Through ACF Repeater Fields in WordPress Tutorial/Guide

Advanced Custom Fields (ACF) is one of the most powerful WordPress plugins for custom content. The repeater field is especially useful when you want to store and loop through sets of structured data. Here’s how to get started with it.

Working with Repeater Fields Using ACF

Imagine a repeater field called "my_repeater_field" with subfields like "sub_field_1" and "sub_field_2". Here's how to fetch them:

Step 1: Check for Repeater Rows

Use the have_rows() function to confirm there’s data to work with:

<?php
if (have_rows('my_repeater_field')) {
    while (have_rows('my_repeater_field')) {
        the_row();
        $val1 = get_sub_field('sub_field_1');
        $val2 = get_sub_field('sub_field_2');

        echo 'Subfield 1: ' . $val1 . '<br>';
        echo 'Subfield 2: ' . $val2 . '<br>';
    }
}
?>

Step 2: Access Subfield Data

Once inside the loop, use get_sub_field() to extract individual field values. This method allows for displaying each entry as needed.

Why Use Repeater Fields?

ACF repeaters simplify the creation of flexible data structures such as sliders, accordions, and grouped content without cluttering your admin panel. The have_rows() and get_sub_field() combo makes front-end rendering effortless.

Helpful Documentation

Use this snippet in your template files to build powerful, repeatable content blocks easily.

๐Ÿ’ก Have a Coding Problem?

Search our archives or reach out to our team for solutions and expert advice.