OK, so I've read like 20 different articles about using a while loop inside another while loop, but still can't get this to work, and I'm about to burst from frustration.

My scenario: using the Advanced Custom Fields plugin along with the WP Coda Slider. My goal is to display a small gallery of images (that are loaded via the ACF plugin, on a custom post type) inside a Coda Slider.

The images in the ACF are also using the Repeater addon for ACF. This requires the use of a while loop to output the images.

Facts: parent field for images: portfolio-images field key for images: image

php that ACF says will display the images:

 <?php while(the_repeater_field('portfolio-images')): ?>
 <a href="<?php the_sub_field('link'); ?>">
 <img src="<?php the_sub_field('image'); ?>" alt="image" />
 <?php endwhile; ?>

I'm already running this loop for the WP Coda Slider:


            <div id="post-<?php the_ID(); ?>" <?php post_class('panel'); ?>>
                <div class="panel-wrapper">
                    <div id="package-tagline-container" class="container_24">
                        <div class="bracket grid_1">{</div>
                            <div id="page-tagline" class="grid_16">
                                <h6><?php the_field('tagline'); ?></h6>
                        <div class="bracket grid_1">}</div>
                        <div id="package-title" class="grid_6">
                            <h4 class="title"><?php the_title(); ?></h4>
                    </div><!-- #package-tagline-container -->

                        <?php the_content(); ?>

                </div> <!-- .panel-wrapper -->
            </div> <!-- .panel -->

         <?php endwhile; else:
     wp_reset_query(); ?>

I don't know what else to try at this point. Any help is very appreciated. Thanks.

3 Answers 3


I would create a custom query for each nested loop and loop on its post data. Similar to what is written about here.

You will probably need to save the post global to a temporary variable so it can be set back ( setup_postdata() ) at the end of the nested look.

  • I am concerned about site performance with this approach, if you have many nested loops. Commented Nov 3, 2011 at 21:21

What version of WP Coda Slider are you using? Are you using the short code or template tag to insert the slider?

The plugin works with nested loops inserted in the post with a shortcode. The normal gallery shortcode works fine.

BTW: I am the author of the plugin and it needs to be updated to use some of the newer WP API.

  • hi chris, thanks for responding. i am using the latest version of the Coda Slider via the template tag. the plugin works great btw, its just trying to add this gallery now that's giving me some trouble. any suggestions are appreciated.
    – jedifunk
    Commented Nov 8, 2011 at 14:37

Have you tried using "while(have_rows())"? That's how I write my repeater fields.

<?php while(have_rows('portfolio-images')): the_row(); ?>
 <a href="<?php the_sub_field('link'); ?>">
  <img src="<?php the_sub_field('image'); ?>" alt="image" />
<?php endwhile; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.