Support

Account

Home Forums Add-ons Repeater Field Random Repeater in a Repeater Reply To: Random Repeater in a Repeater

  • Jonathan, thank you so much. I had to add a few more parameters but we got it there. Thanks again.

    <?php 
    		$i = 0; 
    		while(have_rows('squares')): 
    		the_row();
    			$i++;
    			$repeater = get_sub_field( 'images' );
    			$rand = rand(0, (count($repeater) - 1)); //does not select a specific row but rather just a number
    			?>
    			<a href="<?php the_sub_field('link'); ?>" class="fs-square" style="background-image:url('<?php echo $repeater[$rand]['image']['sizes']['four-square']; ?>')">	
    				<div class="main-text"><?php the_sub_field('main_text'); ?></div>
    				<div class="icon-section">
    					<div class="icon"><?php the_sub_field('icon'); ?></div>
    					<div class="icon-text"><?php the_sub_field('icon_text'); ?></div>
    				</div>
    			</a>
    		<?php endwhile; ?>