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!
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.