I’m coding an event page and have a little issue with outputting data from my nested loops.
The agenda view is supposed to look like so:
Day 1:
Time - Title
- Meta
Time - Title
- Meta
Time - Title
- Meta
Day 2:
Time - Title
- Meta
Time - Title
- Meta
Time - Title
- Meta
My code is as below:
$dates = CFS()->get( 'event_agenda' );
if (!empty($dates)) {
foreach ( $dates as $date ) {
$date_block .= "<div class='date'>" . $date['event_day'] . "</div>";
$sessions = $date['event_sessions'];
foreach ( $sessions as $session ) {
$session_time = $session['event_session_start_time'];
foreach ( $session_time as $key => $label ) {
$session_block .= "<div class='time'>" . $label . "</div><div class='meta'>" . $session['event_session_title'] . $session['event_session_description'] . "</div>";
}
}
$agenda_block .= "<div class='agenda-block'>" . $date_block . $session_block . "</div>";
highlight_string("<?php\n\$data =\n" . var_export($agenda_block, true) . ";\n?>");
return $agenda_block;
}
}
The result of this is only a single day is shown:
I’m pretty sure that I’m generating the blocks in the correct place within the nested loops i.e. I need to get the dates first and then within each date, loop through each session and time and save them. Then output per date.
I’m confused why this is happening and any help would be much appreciated!