Search code examples
phpwordpressadvanced-custom-fieldsacfpro

Advanced Custom Fields : Repeaters


I'm trying to display below using ACF

(There are multiple sections so made this section a repeater) - Section Title ( Under section title there are multiple packages so made this section a repeater as well) -- Package Title -- Price

Everytime when I'm add a section it should display as a new section underneath the previouse section. Instead of that it showing inside of previouse section.

Can you please point me what I'm doing wrong here.

<div class="pricing">
            <?php
                if(have_rows('packages')): 
                    while(have_rows('packages')) : the_row();?>
                <div class="pricing-section">        
                <?php  echo the_sub_field('section_title_and_details'); ?>
                </div>
                
                <div class="pricing-package-container">        
                    <?php if(have_rows('package_details')): 
                                while(have_rows('package_details')) : the_row(); ?>
                    <div class="pricing-packages">
                                <h3><?php echo the_sub_field('package_name'); ?></h3>
                                <h4><?php echo the_sub_field('price'); ?></h4>
                    </div>
                            <?php endwhile;
                        endif;
                    endwhile;
                endif;
                ?>
                </div>
        </div>

Solution

  • As @HowardE Pointed out above, pricing-package-container was closing outside of the loop. Fixed it as below.

    <!-- Custom Feilds -->
            <div class="pricing">
                <?php
                    if(have_rows('packages')): 
                        while(have_rows('packages')) : the_row();?>
                    <div class="pricing-section">        
                    <?php the_sub_field('section_title_and_details'); ?>
                    </div>
                    
                        <div class="pricing-package-container">        
                        <?php if(have_rows('package_details')): 
                                    while(have_rows('package_details')) : the_row(); ?>
                        <div class="pricing-packages">
                                    <h3><?php the_sub_field('package_name'); ?></h3>
                                    <h4><?php the_sub_field('price'); ?></h4>
                        </div>
                                <?php endwhile;
                            endif; ?>
                        </div>
                       <?php endwhile;
                    endif;
                    ?>
            </div>