php - ACF : How to get a random row in a repeater field? -
i'm using wordpress advanced custom fields plugin , trying output random image in repeater field. got far using acf documentation, code seems not work, $image[0] variable empty. ? :)
<?php $rows = get_field('les_gifs' ); // rows $rand_row = $rows[ array_rand( $rows ) ]; // random row $rand_row_image = $rand_row['gif' ]; // sub field value // note // $first_row_image = 123 (image id) $image = wp_get_attachment_image_src( $rand_row_image, 'large' ); // url = $image[0]; // width = $image[1]; // height = $image[2]; echo 'image 0 : '.$image; ?> <?php if($image[0]) : $style= 'style="background-image:linear-gradient(135deg, rgba(0,89,167,0.65) 0%,rgba(23,208,233,0.65) 100%),url('.$image.');"'; else: $style = ''; endif; ?>
turns out made rookie mistake. code works fine. i'm calling outside of loop , forgot add post id.
$rows = get_field('les_gifs', 432 );
this bit solved it
Comments
Post a Comment