Unless I’ve mis-interpreted what you are trying to accomplish, you added the foreach
loop and you don’t need it. Having it run while inside a while
loop seems to be duplicating your intentions. Remove the foreach
loop altogether, delete the first wp_reset_postdata();
, and un-comment the 2nd one:
<div id="carouselTestimonial" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<?php
$cptQuery = new WP_Query($args = [
'post_type' => 'client-testimonial',
'post_status' => 'publish',
'posts_per_page' => -1
]);
$active="active";
while ( $cptQuery->have_posts() ) : $cptQuery->the_post();
setup_postdata( $cptQuery );
$cptID = get_the_ID();
$addTestHomePage = get_field('homepage_testimonial_carousel');
$testComanyName = get_field('client_testimonial_company_name');
$testFirstName = get_field('client_testimonial_client_first_name');
$testLastName = get_field('client_testimonial_client_last_name');
$testTitle = get_field('client_testimonial_client_title');
$testImage = get_field('client_testimonial_client_picture');
if( $testImage ):
$testImgurl = $testImage['url'];
$testImgtitle = $testImage['title'];
$testImgalt = $testImage['alt'];
$testImgcaption = $testImage['caption'];
endif;
$testAltImage = get_field('client_testimonial_secondary_image');
$testQuote = get_field('client_testimonial_quote');
if ($addTestHomePage === "yes") :
?>
<div class="carousel-item <?php echo $active;?>">
<?php echo $cptID; ?>
<div class="row">
<div class="col-3 col-md-3 col-sm-3">
<div class="imagesDiv">
<?php if ($testImage) { ?>
<img class="images" src="<?php echo $testImgurl; ?>" title="<?php echo $testImgtitle; ?>" alt="<?php echo $testImgalt; ?>">
<?php } else { ?>
<img class="images" src="<?php echo get_home_url(); ?>/wp-content/uploads/2023/08/<?php echo $testAltImage; ?>.webp" title="Stock Image of a Profile Picture" alt="This is a stock photo">
<?php } ?>
</div>
</div>
<div class="col-9 col-md-3 col-sm-9">
<?php if ($testQuote) : ?>
<div class="largeQuote"></div>
<div class="testimonialQuote">
<?php echo $testQuote; ?>
</div>
<div class="byline"><?php echo $testFirstName; ?> <?php echo $testLastName; ?>, <?php echo $testTitle; ?></div><br />
<div class="byline"><?php echo $testComanyName; ?></div>
<?php endif; ?>
</div>
</div>
</div>
<?php
$active="";
endif; //homepage carousel check
endwhile;
wp_reset_postdata(); ?>
</div>
</div>
<a class="carousel-control-prev" href="#carouselTestimonial" role="button" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true">Prev</span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselTestimonial" role="button" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true">Next</span>
<span class="sr-only">Next</span>
</a>