Reputation: 11
I need help with a foreach within a foreach. I'm using the Wordpress plug-in, Advanced Custom Fields to create Repeater Fields inside of repeater fields. I'm then displaying (or attempting to display) them on the frontend outside the main loop using the code below:
<?php
//Loop Through Days and Sights
$days = get_field('day_and_highlights');
$n = 0;
if($days){
echo '<div>';
foreach($days as $day){
$n++;
echo '<h2> Day ' . $n . ': ' . $day['destination_dropdown'] . '</h2><br/>';
//Loop through Attractions
<?php
$attractions = get_field('attraction_list');
if($attractions){
echo '<ul class=\"list_attractions\">';
foreach($attractions as $attraction){
echo '<li class=\"single_attraction\"><p>' . $attraction['add_attraction'] . '</p></li>';
}; //end foreach
echo '</ul>';
}; //endif
};
echo '</div>';
};
?>
The first foreach echo's everything spot on. The inner foreach doesn't do jack. I can't get it to do anything.
Upvotes: 0
Views: 207
Reputation: 200
You have an extra php tag:
//Loop through Attractions
<?php
$attractions = get_field('attraction_list');
if($attractions){
Try removing it.
Also, your IF and FOREACH statements should not end in semicolons:
}; //endif
http://www.php.net/manual/en/control-structures.foreach.php
Upvotes: 2