Home Forums Add-ons Repeater Field Random image repeater


Random image repeater

  • Hi, I’m trying to create a random repeater using this method, but the output is blank. Can anyone spot where I’m going wrong?

    	$rows = get_field('homepage_images' ); // get all the rows
    	$rand_row = $rows[ array_rand( $rows ) ]; // get a random row
    	$rand_row_image = $rand_row['image_set']; // get the sub field value 
    	$image = wp_get_attachment_image_src( $rand_row_image, 'full' );
    	// url = $image[0];
    	// width = $image[1];
    	// height = $image[2];
       <header class="hero" style="background-image: url(<?php echo $image[0]; ?>)">
  • you’re using array_rand() wrong

    $rand_row = array_rand($rows, 1); // get a random row

  • Thanks I got it sorted – I was using URL as the image type. Changed it to ID and it worked.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Random image repeater’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.