Why is the carousel skips the last element in the loop and how to fix it?

Hello! There are implemented functions, tied to the hybrid carousel and tabs - fiddle
Moved it to wordpress and set the elements using the plugin custom fields. All is good, but now everything is working (the spinning carousel) only up to the penultimate element and then returns to the first. As this point, correct?
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval>

 <?php $test = new WP_Query([
 'post_type' =--> 'gates',
 'post_status' => 'publish',
 'posts_per_page'=> -1,
 'order' => 'ASC'
 ]); ?>
 <?php $i=0; ?>

 <!-- Indicators -->
 <ol class="carousel-indicators"> 
 <?php while($test--->have_posts()): ?>
 <?php $test--->the_post(); ?>
 <li data-target="#myCarousel" data-slide-to="<?php echo $i; ?>" <?php if($i="=0)" : echo ' class="active" '; endif; ?>>
 <a data-toggle="pill" class="js-link js-link-<?php echo $i; ?>" href="#<?php echo ++$i; ?>"><?php the_post_thumbnail('full'); ?></a>

 <?php endwhile ?>
 <?php wp_reset_query() ?>

 <!-- Wrapper for slides -->
 <div class="carousel-inner" role="listbox">
 <?php $i = 0;
 while($test--->have_posts()): ?>
 <?php $test--->the_post(); ?>

 $gallery = get_post_meta(get_the_ID(), 'gallery_types', true);
 $images = get_field('gallery_types');
 if( $images ): ?>
 <div class="item <?php if($i==0) : echo 'active'; endif; ?>">
 <?php foreach( $images as $image ): ?>
 <img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>">
 <?php endforeach; ?>
 <?php $i++; ?>
 <?php endif; endif; ?>

 <?php endwhile ?>
 <?php wp_reset_query() ?>
 <!-- Left and right controls -->
 <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"></a>
 <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"></a>
July 2nd 19 at 17:45
1 answer
July 2nd 19 at 17:47
At first glance it seems that in the block .carousel-indicators displays control elements simply by the presence of all posts and gates, and the output unit of blocks .item condition is based on availability $gallery and $images in it. You definitely in all positions galleries have at least one picture?
Yes, the taboo on it can go, but through the carousel no..
I somehow think that the problem may be at the junction of the `$i++` and `++$i` - Shaun.Doyle commented on July 2nd 19 at 17:50
: checked - indeed, somewhere it disappeared gallery - Shaun.Doyle commented on July 2nd 19 at 17:53

Find more questions by tags SliderWordPress