I'm developing a small online-courses website for a friend and got stuck with ACF repeater field!
Here's my code to display the course dates table:
<?php
$rows = get_field('dates');
$i = 1;
if($rows) { ?>
<table class="specs">
<thead>
<tr>
<th colspan="5">Course Dates</th>
</tr>
</thead>
</tbody>
<?php
foreach($rows as $row) {
echo '<tr>';
echo '<td>' . $i . '</td>';
echo '<td>' . $row['start_date'] ;
// Check, if "end_date" field is not empty
if( $row['end_date']) {
echo ' - ' . $row['end_date'] . '</td>';
} else {
echo '</td>';
}
echo '<td>10am – 5pm</td>';
echo '<td>£' . $row['course_price'] .'</td>';
echo '<td><a href="#" class="button orange">Book Now</a></td>';
echo '</tr>';
$i++;
}; ?>
</tbody>
</table>
<?php }
This code outputs a nice table:
The only thing I can't figure out is how to check ['start_date'] sub_field against current date and display courses in the loop with valid dates only.
So, basically, I need to auto delete or just exclude from the loop a whole table row if the [start_date] sub_field is not valid any more!
Is there any workaround for this?