Created
April 13, 2020 01:52
-
-
Save bstonedev/40a108cfec5258a8827db46a491e3ece to your computer and use it in GitHub Desktop.
Different loops thru ACF Repeater Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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