Support

Account

Home Forums ACF PRO Help with Nested Repeaters

Solving

Help with Nested Repeaters

  • Hello,

    I’m using a couple repeaters that is using an accordion and I can’t figure out what I’m doing wrong.

    Here is the code I am using –

    
    <div class="minutes">
    <?php 
    // check for rows (parent repeater)
    if( have_rows('ma') ): ?>
                        
    <?php 
    // loop through rows (parent repeater)
    while( have_rows('ma') ): the_row(); ?>
                         
    <h2><?php if( get_sub_field('ma_department_name') ): ?>
        <?php the_sub_field('ma_department_name'); ?>
    <?php endif; ?></h2>
    	
    <?php 
    // check for rows (sub repeater)
    if( have_rows('ma_meeting_year') ): ?>	
    <?php 
    // loop through rows (sub repeater)
    while( have_rows('ma_meeting_year') ): the_row(); ?>
    
    <ul>
    	
    <button class="accordion"> 	
    <?php if( get_sub_field('ma_year') ): ?>
        <?php the_sub_field('ma_year'); ?>
    <?php endif; ?>	
    </button>
    	
    <div class="panel">	
    <li>
    	
    <?php 
    // check for rows (sub repeater)
    if( have_rows('ma_files') ): ?>
    	
    <?php 
    // loop through rows (sub repeater)
    while( have_rows('ma_files') ): the_row(); ?>
                                       
    <?php if( get_sub_field('ma_date') ): ?>
        <?php the_sub_field('ma_date'); ?>
    <?php endif; ?>
    
    <?php if( get_sub_field('ma_title') ): ?>
        <?php the_sub_field('ma_title'); ?>
    <?php endif; ?>
    	
    <?php if( get_sub_field('ma_minutes') ): ?>
        <a>" target="_blank">Minutes</a>
    <?php endif; ?>
    		
    <?php
    $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; ?>
    
    <?php endif; //if( get_sub_field('ma_year') ): ?>                         
    <?php endwhile; // while( has_sub_field('ma_meeting_year') ): ?>
    <?php endif; // if( get_field('ma_meeting_year') ): ?>
    	
    	<?php endwhile; // while( has_sub_field('ma') ): ?>
    <?php endif; // if( get_field('ma') ): ?>
    		
    </div>		
    

    I’m not sure what I’m doing wrong but the first repeater doesn’t show correctly and it’s showing everything in the accordion that should be hidden.

    The other 2 show correctly but only hide the first entry in the accordion.

    Here is the website – https://collier.tfm-dev.com/government/agendas-minutes/

    I would appreciate any help!!

  • 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>
    
  • Thank you John for your response and looking at it!

    I ended up writing things out to make it more clear and found my errors. I got it to work. Thanks again for looking!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.