Last active
January 26, 2022 15:43
-
-
Save chriswagoner/e2babf5e118db2350c480576f20e6c0b to your computer and use it in GitHub Desktop.
ACF_Repeater_Fields
This file contains 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
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