Home › Forums › Add-ons › Repeater Field › Display random rows in repeater while limiting the number shown › Reply To: Display random rows in repeater while limiting the number shown
I’m assuming you mean on the front-end / display end and not the admin panel. If I’m mistaken please reply back and we can come up with a different solution. Additionally I don’t have Pro but from what I remember the repeater field is simply an array so instead of using the helper functions you can get the raw results using get_field()
.
// Get our repeater values
$repeater_arr = get_field( 'repeater-name-or-key', $post_id );
/**
* We're going to shuffle the repeater array ( randomize the whole thing )
* Which is done by reference, so lets put it in a temporary value
* So we don't mess with our original repeater_arr value
*/
$temp_arr = $repeater_arr;
shuffle( $temp_arr );
// Grab up to 10 values of the array
$random_slice = array_slice( $temp_arr, 0, 10 );
// Loop through the random subfields
foreach( $random_slice as $subfield ) {
echo $subfield['title'];
}
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.