Skip to content

Instantly share code, notes, and snippets.

@chriswagoner
Last active January 26, 2022 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswagoner/e2babf5e118db2350c480576f20e6c0b to your computer and use it in GitHub Desktop.
Save chriswagoner/e2babf5e118db2350c480576f20e6c0b to your computer and use it in GitHub Desktop.
ACF_Repeater_Fields
add_shortcode( "the_shortcode", "the_function" );
function the_function() {
ob_start();
// Run the loop - Do we have a Repeater field?
if ( have_rows( 'repeater_field_name' ) ) :
echo '<div class="myclass">'; // Optional if you want to output before the fields
// Lock into the Repeater field and it's subfields
while ( have_rows( 'repeater_field_name' ) ) : the_row();
// Optional Echo if you want to wrap each row
echo '<div class="myclass2">';
// This is where you can control the subfield output
if ( get_sub_field( 'repeater_sub_field_name' ) ) :
echo '<div class="myclass--card">';
$sub_image = get_sub_field('repeater_sub_field_name');
echo '<img src="'.$sub_image.'" />'; // If you have an Image
echo '</div>';
endif;
echo '</div>';
endwhile;
echo '</div>';
endif;
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment