Support

Account

Home Forums ACF PRO Help with Nested Repeaters Reply To: Help with Nested Repeaters

  • You have some serious nesting issues in your code that I’m not sure how to fix, but adding some whitespace to show the nesting makes them more visible.

    
    <div class="minutes">
      <?php 
        // check for rows (parent repeater)
        if (have_rows('ma')):
          // loop through rows (parent repeater)
          while (have_rows('ma')):
            the_row();
            ?>
              <h2>
                <?php 
                  if( get_sub_field('ma_department_name') ):
                    the_sub_field('ma_department_name');
                  endif;
                ?>
              </h2>
            <?php 
            // check for rows (sub repeater)
            if( have_rows('ma_meeting_year') ):
              // loop through rows (sub repeater)
              while( have_rows('ma_meeting_year')):
                the_row();
                ?>
                  <ul>
                    <button class="accordion">   
                    <?php 
                      if( get_sub_field('ma_year') ): 
                        the_sub_field('ma_year');
                      endif;
                    ?>  
                    </button>
                    <div class="panel">  
                      <li>
                        <?php 
                          // check for rows (sub repeater)
                          if( have_rows('ma_files') ):
                            // loop through rows (sub repeater)
                            while( have_rows('ma_files') ):
                              the_row();
                              if( get_sub_field('ma_date') ):
                                the_sub_field('ma_date');
                              endif;
                              if( get_sub_field('ma_title') ):
                                the_sub_field('ma_title');
                              endif;
                              if( get_sub_field('ma_minutes') ):
                                ?><a>" target="_blank">Minutes</a><?php 
                              endif;
                              $file = get_sub_field('ma_agenda');
                              if( $file ):
                                 $url = wp_get_attachment_url( $file );
                                ?><a>" target="_blank">Agenda</a><?php 
                              endif;
                              ?>
                      </li>
                    </div>
                  </ul>
                              <?php 
                            endwhile; // end while( have_rows('ma_files') ):
                          endif; // end if( have_rows('ma_files') ):
              endwhile; // end while( have_rows('ma_meeting_year')):
            endif; // end if( have_rows('ma_meeting_year') ):
          endwhile; // end while (have_rows('ma')):
        endif; // end if (have_rows('ma')):
      ?>
    </div>