Support

Account

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