Pull Random Image From Repeater Field. This script pulls an image from a repeater field and allows it to be used as the page background image. This was used on the homepage of the tpf.org website.
<?php
// Random Repeater Row
// SRC: http://support.advancedcustomfields.com/forums/topic/random-repeater/
$rows = get_field('background_images');
if($rows){
shuffle($rows);
$i = 0;
foreach($rows as $row){
$image = wp_get_attachment_image_src( $row['background_image'], 'medium');
?>
<section class="section-1" style="background: url('<?php echo $image[0]; ?>'); background-repeat:no-repeat; background-position:center center; background-size:cover;">
<?php
if (++$i == 1) break;
}
}
?>
Usage:
TPF homepage background image.