Skip to content

Instantly share code, notes, and snippets.

@jonlow
Created January 9, 2016 04:42
Show Gist options
  • Save jonlow/15a9d302cc75ba4738b2 to your computer and use it in GitHub Desktop.
Save jonlow/15a9d302cc75ba4738b2 to your computer and use it in GitHub Desktop.
Loop Advanced Custom Fields repeater
<?php
// check if the repeater field has rows of data
if( have_rows('related_pages') ):
// loop through the rows of data
while ( have_rows('related_pages') ) : the_row();
$postobject = get_sub_field('page');
$post = $postobject;
setup_postdata( $post );
?>
<div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<span>Post Object Custom Field: <?php the_field('map_location'); ?></span>
</div>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endwhile;
else :
// no rows found
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment