Answers for "acf get repeater"

PHP
9

acf repeater

<?php

// ACF REPEATER - BASIC LOOP

// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):

 	// loop through the rows of data
    while ( have_rows('repeater_field_name') ) : the_row();

        // display a sub field value
        the_sub_field('sub_field_name');

    endwhile;

else :

    // no rows found

endif;

?>
Posted by: Guest on April-29-2020
1

acf repeater

<?php 
$rows = get_field('repeater_field_name');
if( $rows ) {
    echo '<ul class="slides">';
    foreach( $rows as $row ) {
        $image = $row['image'];
        echo '<li>';
            echo wp_get_attachment_image( $image, 'full' );
            echo wpautop( $row['caption'] );
        echo '</li>';
    }
    echo '</ul>';
}
Posted by: Guest on July-17-2020
2

acf repeater

<?php 

$rows = get_field('repeater_field_name');
if($rows)
{
	echo '<ul>';

	foreach($rows as $row)
	{
		echo '<li>sub_field_1 = ' . $row['sub_field_1'] . ', sub_field_2 = ' . $row['sub_field_2'] .', etc</li>';
	}

	echo '</ul>';
}
Posted by: Guest on June-02-2020
0

acf repeater

// ACF REPATER - ADVANCED LOOP

<?php if( have_rows('repeater_field_name') ): ?>

	<ul class="slides">

	<?php while( have_rows('repeater_field_name') ): the_row(); 

		// vars
		$image = get_sub_field('image');
		$content = get_sub_field('content');
		$link = get_sub_field('link');

		?>

		<li class="slide">

			<?php if( $link ): ?>
				<a href="<?php echo $link; ?>">
			<?php endif; ?>

				<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />

			<?php if( $link ): ?>
				</a>
			<?php endif; ?>

		    <?php echo $content; ?>

		</li>

	<?php endwhile; ?>

	</ul>

<?php endif; ?>
Posted by: Guest on April-29-2020

Browse Popular Code Answers by Language