Support

Account

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'];
    }