Home › Forums › Add-ons › Repeater Field › A repeater in random order including select fields › Reply To: A repeater in random order including select fields
This is the updated code:
<?php
$rows = get_field('slider_image' );
$sub_field = has_sub_field('slider_image');
$rand_row = $rows[ array_rand( $rows ) ];
$logo_colour = get_sub_field('logo_colour');
$caption = get_sub_field('the_caption');
$template_directory = bloginfo('template_directory');
if($rows) // if slider_image exits
{
echo '<h3>Header</h3>';
echo '<ul>';
while($sub_field) // enables us to use get_sub_field
{
$rows = $rand_row['slider_image']; // random order of rows
foreach ($rows as $row) {
echo '<li>' . $caption . '</li>'; // displays caption
if(($logo_colour) == "white") { // displays white logo if selected, else grey
echo '<li><img src="'. $template_directory . '/logo_white.png" /></li>';
} else {
echo '<li><img src="'. $template_directory . '/logo_grey.png" /></li>';
}
}
echo '</ul>';
}
}
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.