Home › Forums › General Issues › How to Randomize This? › Reply To: How to Randomize This?
Took out $paperCounter for now to try and get 1 random one pulled and have it functioning with the exception of the get_image_with_alt line. Any clue how I could pull 2 randoms, and adjust the line get_image_with_alt to be random? Feel like I am getting close but need a bit of help.
function getLatestPhotos() {
if(get_field('photos', 34)) {
$rows = get_field('photos', 34);
$row_count = count($rows);
$i = rand(0, $row_count - 1);
echo $rows[$i]['sub_field_name'];
$latestPhotos .= '<a href="/photos/">';
$latestPhotos .= get_image_with_alt('cover', get_the_ID(), '');
$latestPhotos .= '<p>'.$rows[$i]['title'].'</p>';
$latestPhotos .= '<span>'.$rows[$i]['name'].'</span>';
$latestPhotos .= '</a>';
}
return $latestPhotos;
}
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.