Site icon Hip-Hop Website Design and Development

Randomize testimonials using repeater field

I created a testimonial box on my website using the ACF repeater field. My goal is to add a few testimonials, but only showing one at a time, with a different testimonial coming up each time the page is loaded.

I used shuffle(), however, all of the testimonials at once, stacked on top of each other. Can someone take a look at the code and let me know what I did wrong?

       <section class="mt-5">
        <?php $testimonials = get_field( 'testimonial'); ?>
        <?php if ( is_array( $testimonials ))  { ?>
        <?php shuffle($testimonials); // Randomize ?>
              
              <div class="col-lg-12 mt-3 front-page-testimonial extended-bold-l">
              <?php foreach($testimonials as $testimonial) { ?>
                <p><?php echo $testimonial['quote']; ?>
                </p>
                <p class="extended-bold-l mt-4"><?php echo $testimonial['name']; ?></p>
                <p class="extended-bold-m" style="margin-top:-.85em"><?php echo $testimonial['job_title']; ?>, <?php echo $testimonial['client']; ?></p>
            

                <?php } ?>
            <?php } ?>
          </div>
       </section>