Thanks for your response. I got some help, and here is the final code that we went with below. I’m not sure what the ’76’ does, but hope this helps others in the future.
<?php if( have_rows('title', 76) ): ?>
<?php
// Get the repeater field
$repeater = get_field( 'title', 76 );
// Get a random row.
$random_row = array_rand( $repeater, 1 );
// Get subfields
$image = $repeater[$random_row]['image'];
$link = $repeater[$random_row]['link'];
?>
<?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 endif; ?>
I know this is 4-5yrs old …
I’m having similar issues. I have the typical repeater (title, image, link) that I would like to randomize. All of my images are showing up all at once. Could someone please help me roll this row randomization into my existing code below?
<?php if( have_rows('billboard') ): ?>
<?php while( have_rows('billboard') ): the_row();
// vars
$image = get_sub_field('image');
$link = get_sub_field('link');
?>
<?php if( $link ): ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<img class="billboard" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php if( $link ): ?>
</a>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>