<?php
$i=1;
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<!-- individual panel -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#faqs" href="#<?php the_ID(); ?>">
<?php the_title(); ?>
</a>
</h4>
</div>
<div id="<?php the_ID(); ?>" class="panel-collapse collapse <?php if ($i==1) { echo 'in'; } ?>">
<div class="panel-body">
<?php the_field('answer'); ?>
</div>
</div>
</div>
<!-- /individual panel -->
<?php $i++; endwhile;
?>
It should be $i==1
not $i=1
in your if condition
When you do $i=1
it means you are assigning value 1 to $i , so every time it is successfully satisfying condition.
Here is Comparison Operators 😀
0
solved PHP loop to echo certain div class on first round only