We want to replace a slider with a clickable random image. So far I have half of this working using the below code that pulls one image from the ACF gallery and displays it.
What I can't seem to find is how to then use the image's custom link (as assigned when looaded into the WP media gallery), so that the image is also clickable (where the user loads the image and assigns the desired custom link).
Anyone have any idea how to get this to work?
Cheers!
<?php
$images = get_field('gallery', '', false);
$size = 'full';
$rand = array_rand($images ?? [null]);
if( $images ): ?>
<?php echo wp_get_attachment_image( $images[$rand], $size, "", $attr ); ?>
<?php endif; ?>
Solved! For those that want the solution, here is the code I bashed together to make an ACF Repeater powered random image with a custom link. Thanks @MindBorn for getting my brain working :)
<?php
$random_images = get_field('random_image_row');
shuffle($random_images);
$random_img_url = $random_images[0]['banner']['url'];
$random_image_link = $random_images[0]['image_link'];
?>
<div style="width:100%;">
<a href="<?php echo $random_image_link; ?>" > <img src="<?php echo $random_img_url; ?>" height="400" width="1920" /></a>
</div>