Multiple Bootstrap Tabs on one page using ACF Repeater Field

I have two instances of Bootstrap Tabs on one page (using the understrap theme and a child theme). I’ve updated the two tab groups to have different IDs but for some reason (haha) the second instance of the Bootstrap Tabs, the first tab’s content never goes away. This is because the active/show classes never get removed when the other tabs are clicked.

On the second instance of tabbed content, I can click on the other tabs and it loads the content under the first tab’s content. The first tab’s content (of second instance) never goes away (the active class stays put).

One other thing I noticed, If I tell it to set the active on $i or $row == 2 it will display that content only on page load but then when I go to click on the first tab, no tab-panel content will display. The active never gets placed on that first tab-panel.

First Tabbed Content:

<div class="tabbed-col">
<script>
    $(document).ready(function(){
       $("#ai-tabs a").click(function(e){
         e.preventDefault();
         $(this).tab("show");
       });
    });
</script>

<?php if( have_rows('how_to_prepare_listing') ):
$i = 1; // Set the increment variable
echo '<ul class="nav nav-tabs" id="ai-tabs" role="tablist">';
                                                        
// loop through the rows of data for the tab header
while ( have_rows('how_to_prepare_listing') ) : the_row();
$header = get_sub_field('tab_title');
$content = get_sub_field('tab_information');
?>
    <li class="nav-item">
      <a class="nav-link <?php if($i == 1) echo 'active';?>" id="<?php echo sanitize_title($header); ?>-tab" data-toggle="tab" href="#<?php echo sanitize_title($header); ?>" role="tab" aria-controls="<?php echo sanitize_title($header); ?>" aria-selected="true"><?php echo $header; ?></a>
    </li>            
    <?php   $i++; // Increment the increment variable

endwhile; //End the loop 
                                                        
echo '</ul>';
echo '<div class="tab-content" id="aiTabContent">';
$i = 1; // Set the increment variable
                                                        
// loop through the rows of data for the tab content
while ( have_rows('how_to_prepare_listing') ) : the_row();
$header = get_sub_field('tab_title');
$content = get_sub_field('tab_information');
?>              
<div class="tab-pane fade show <?php if($i == 1) echo 'active';?>" id="<?php echo sanitize_title($header); ?>" role="tabpanel" aria-labelledby="<?php echo sanitize_title($header); ?>-tab"><?php echo $content; ?></div>
                                                        
<?php   $i++; // Increment the increment variable           
endwhile; //End the loop                                    
echo '</div>';
                                                        
else :
// no rows found
endif; ?>
</div><!--.tabbed-col-->

Second Tabbed Content on page:

<div class="tabbed-col">
  <script>
    $(document).ready(function(){
        $("#ai-tabs-second a").click(function(e){
            e.preventDefault();
            $(this).tab("show");
        });
        
    });
  </script>
  <?php if( have_rows('second_how_to_prepare_listing') ):
      $row = 1; // Set the increment variable
      echo '<ul class="nav nav-tabs" id="ai-tabs-second" role="tablist">';
      
      // loop through the rows of data for the tab header
          while ( have_rows('second_how_to_prepare_listing') ) : the_row();
              $secondheader = get_sub_field('second_tab_title');
              $secondcontent = get_sub_field('second_tab_information');
      ?>
      <li class="nav-item">
            <a class="nav-link <?php if($row == 1) echo 'active';?>" id="<?php echo sanitize_title($secondheader); ?>-tab" data-toggle="tab" href="#<?php echo sanitize_title($secondheader); ?>" role="tab" aria-controls="<?php echo sanitize_title($secondheader); ?>" aria-selected="true">
              <?php echo $secondheader;?>
            </a>
      </li>            
      <?php   $row++; // Increment the increment variable

      endwhile; //End the loop 
      
      echo '</ul>';

      echo '<div class="tab-content" id="aiTabContentSecond">';
      $row = 1; // Set the increment variable
      
      // loop through the rows of data for the tab content
      while ( have_rows('second_how_to_prepare_listing') ) : the_row();
        $secondheader = get_sub_field('second_tab_title');
        $secondcontent = get_sub_field('second_tab_information');
      ?>                
        <div class="tab-pane fade show <?php if($row == 1) echo 'active';?>" id="<?php echo sanitize_title($secondheader); ?>" role="tabpanel" aria-labelledby="<?php echo sanitize_title($secondheader); ?>-tab"><?php echo $secondcontent;?></div>
      
      <?php   $row++; // Increment the increment variable           
      endwhile; //End the loop                                  
      echo '</div>';
    else :
        // no rows found
    endif; ?>

</div><!--.tabbed-col-->

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật