Skip to content

Instantly share code, notes, and snippets.

@bstonedev
Created April 13, 2020 01:52
Show Gist options
  • Save bstonedev/40a108cfec5258a8827db46a491e3ece to your computer and use it in GitHub Desktop.
Save bstonedev/40a108cfec5258a8827db46a491e3ece to your computer and use it in GitHub Desktop.
Different loops thru ACF Repeater Fields
<?php
/*
// Method 0: while-loop
*/
if( have_rows('repeater_field_name') ):
while ( have_rows('repeater_field_name') ) : the_row();
?>
<h2>Sub Field: <?php the_sub_field('sub_field_name'); ?></h2>
<?php
endwhile;
endif;
?>
<?php
/*
/* Method 1: single-line-while-loop
*/
if( have_rows('team_member') ): while( have_rows('team_member') ): the_row(); ?>
<h2>Sub Field: <?php the_sub_field('sub_field_name'); ?></h2>
<?php endwhile; endif; ?>
<?php
/*
/* Method 2: for-each-loop
*/
$rows = get_field('repeater_field_name');
if($rows):
foreach($rows as $row): ?>
<h2>Sub Field: <?php echo $row['sub_field_name']; ?></h2>
<img src="<?php echo $row['sub_field_name']['url']; ?>" >
<?php endforeach; endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment