Home › Forums › General Issues › How to Randomize This? › Reply To: How to Randomize This?
Ok, I simplified this and got the random part to work but now it is pulling two identical random items vs. 2 different random items. How can I fix this?
function getLatestBooks() {
if(get_field('books', 34)) {
$rows = get_field('books', 34);
$row_count = count($rows);
$i = rand(0, $row_count - 1);
echo $rows[$i]['sub_field_name'];
$paperCounter = 0;
while(has_sub_field('books', 34) && $paperCounter < 2) {
$latestBooks .= '<p>'.$rows[$i]['cover'].'</p>';
$latestBooks .= '<p>'.$rows[$i]['title'].'</p>';
$paperCounter++;
}
$latestBooks .= '</ul>';
}
return $latestBooks;
}
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.