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?
<?php
$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]; ?>)">
</header>
you’re using array_rand() wrong
$rand_row = array_rand($rows, 1); // get a random row
http://php.net/manual/en/function.array-rand.php
Thanks I got it sorted – I was using URL as the image type. Changed it to ID and it worked.