Home › Forums › Add-ons › Repeater Field › Repeater sorted by Date › Reply To: Repeater sorted by Date
I’m getting closer, I think. I’ve gotten the month names to create their own rows and cells within the table in the proper order, but now the code is limiting the results on the table to entries in the current month (February).
What I’m trying to do is echo month name on its own row before array entries for that month, and if it is not the start of a new month, echo the entries in the array in individual TD elements.
Any thoughts would be helpful, I think I’m just not good enough with PHP to figure this one out alone.
<table id="race-calendar">
<thead>
<tr>
<th>Date</th>
<th>Race Name</th>
<th>Location</th>
<th>Men's/Women's/Both</th>
</tr>
</thead>
<?php
$repeater = get_field('races');
foreach( $repeater as $key => $row )
{
$column_id[ $key ] = $row['race_date'];
}
array_multisort( $column_id, SORT_ASC, $repeater );
$currMonth = "start";
foreach( $repeater as $row )
{
$date = DateTime::createFromFormat('Ymd', $row['race_date']);
if ($currMonth != $date->format('F'))
{
echo '<tr><td colspan="2"><h2>' . $date->format('F') . '</h2></td></tr><br>';
$currMonth = $date->format('F');
}
else {
echo '<tr class="race">';
echo '<td class="cell">' . $date->format('m/d') . '</td>';
echo '<td class="cell"><h2>' . $row['race_name'] . '</h2></td>';
echo '<td class="cell">' . $row['race_location'] . '</td>';
echo '<td class="cell">' . $row['race_gender'] . '</td>';
echo '</tr>';
}
}
?>
</table>
Thanks!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.