Filter WordPress content with a custom repeater field loop.
<?php
function ccd_custom_content_loop() {
ob_start();
if ( have_rows( 'repeater_field_name' ) ) :
echo '<ul class="slides">';
while ( have_rows( 'repeater_field_name' ) ) : the_row();
// vars
$image = get_sub_field( 'image' );
$content = get_sub_field( 'content' );
$link = get_sub_field( 'link' );
echo '<li class="slide">';
if ( $link ) :
echo '<a href="' . $link . '">';
endif;
echo '<img src="' . $image['url'] . 'alt="' . $image['alt'] . '" />';
if ( $link ) :
echo '</a>';
endif;
echo $content;
echo '</li>';
endwhile;
echo '</ul>';
endif;
return ob_get_clean();
}
function ccd_custom_content_filter( $content ) {
$custom_content = ccd_custom_content_loop();
if ( is_singular( 'my-cpt' ) && in_the_loop() && is_main_query() ) {
return $custom_content;
}
return $content;
}
?>
WordPress Snippet
Modfied from the Advanced Loop example in the Advanced Custom Fields documentation.