Advanced Custom Fields (ACF) repeater fields allow great flexibility for developers in providing easy-to-use interfaces for repetitious information that users sometimes need to edit directly. Using this nested data isn’t too difficult, but can be confusing for new WordPress/PHP developers.
We’ll want to separate out each row of the parent field and output the repeater subfield information, if they are available. First we check if any rows are present on our parent field using the have_rows()
function, then retrieve the contents of each row’s subfields in separate variables for use in the template:
<?php if( have_rows( 'parent_field_name' ) ): ?> <div class="repeater-field-wrapper"> <?php while( have_rows( 'parent_field_name' ) ): the_row(); // Get sub fields from each row $subfield_name = get_sub_field('subfield_field_name'); // Check if subfield has a value and output as desired if( $subfield_name ): ?> <h2><?php echo $subfield_name; ?></h2> <?php endif; endwhile; ?> </div><!-- END .repeater-field-wrapper --> <?php endif; ?>