Use this below code. I have done this below code with some modification with Questioner’s code. Now it is working.
<div id="carousel" class="carousel slide" data-ride="carousel" data-interval="3000">
<!-- Carousel items -->
<div class="carousel-inner">
<?php $slider = new WP_Query(array(
'post_type' => 'slide',
'posts_per_page' => -1,
)); ?>
<?php
if ( have_posts() ) {
$x=0;
while ( $slider->have_posts() ) {
$x++;
$slider->the_post(); ?>
<div class="<?php if($x==1){echo 'active';} ?> item">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(); ?>
<div class="carousel-caption d-none d-md-block">
<h4> <i class="material-icons">
<?php the_title(); ?>
</i> </h4>
</div>
<?php endif; ?>
</div>
<?php } // end while
} // end if
?>
</div>
<!-- Carousel nav -->
<ol class="carousel-indicators">
<?php for($i=0; $i<$x; $i++ ) { ?>
<li data-target="#carousel" data-slide-to="<?php echo $i; ?>" class="<?php if($i==0){ echo 'active'; }?>"></li>
<?php } ?>
</ol>
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a>
</div>