Title: Loop inside Loop doesn&#039;t work properly
Last modified: August 30, 2016

---

# Loop inside Loop doesn't work properly

 *  Resolved [duytr](https://wordpress.org/support/users/duytr/)
 * (@duytr)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/loop-inside-loop-doesnt-work-properly/)
 * Hi
 * I have this loop in side loop:
 *     ```
       $sections = CFS()->get( 'extra_sections' );
       		/* Section Loop*/
       		foreach ( $sections as $section)?>
       		<hr class="decorative">
       		<?php
       		{
   
       		?>
       				<div class="about-section about-display">
       					<h2><?php echo $section['section_name']?></h2>
       					<?php echo $section['section_content'];
       					/*Parts of a Section */
       					foreach ( $section['section_parts'] as $sectionPart) {
       					?>
       						<div class="section-part about-display">
       							<h3><?php echo $sectionPart['part_name']?></h3>
       							<?php echo $sectionPart['part_content'];?>
       						</div>
       					<?php
       					}
       					?>
       				</div>
       		<?php
       		}
       		?>
       ```
   
 * It works well when there is one section. However, it doesn’t work when I add 
   multiple sections. Same thing happens if I add multiple section parts.
    This 
   is the warning from debug bar: Invalid argument supplied for foreach() require(‘
   wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/
   themes/andresportfolio/about.php’)
 * [https://wordpress.org/plugins/custom-field-suite/](https://wordpress.org/plugins/custom-field-suite/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * (@mgibbs189)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/loop-inside-loop-doesnt-work-properly/#post-6806484)
 * What is the raw output when you run:
 *     ```
       var_dump( CFS()->get( 'extra_sections' ) );
       ```
   
 *  [veerendratikhe](https://wordpress.org/support/users/veerendratikhe/)
 * (@veerendratikhe)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/loop-inside-loop-doesnt-work-properly/#post-6806528)
 * Hello Matt,
 * I am also having similar problem, one loop works fine but other loop inside parent,
   doesn’t work, it shows array length in side parent array when i do var dump of
   parent array.
 * [http://websitetutorials.grafix.gr/cms/wordpress-2/wordpress-plugins/custom-field-suite/](http://websitetutorials.grafix.gr/cms/wordpress-2/wordpress-plugins/custom-field-suite/)
   
   btw I found out this tutorial and I got clue about how to work it out. Thanks
   for great plugin Matt !

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Loop inside Loop doesn't work properly’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-field-suite.svg)
 * [Custom Field Suite](https://wordpress.org/plugins/custom-field-suite/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-field-suite/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-field-suite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-field-suite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-field-suite/reviews/)

## Tags

 * [foreach](https://wordpress.org/support/topic-tag/foreach/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 2 replies
 * 3 participants
 * Last reply from: [veerendratikhe](https://wordpress.org/support/users/veerendratikhe/)
 * Last activity: [9 years, 12 months ago](https://wordpress.org/support/topic/loop-inside-loop-doesnt-work-properly/#post-6806528)
 * Status: resolved