Home › Forums › Add-ons › Repeater Field › Repeater sorted by Date › Reply To: Repeater sorted by Date
Oh wait this might be working…I am new to PHP….
notice the instances of “$currMonth != $date->format(‘F’)”, I imagine this makes the function return a string, is that right?
<?php
$repeater = get_field('race_event');
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']);
$website_url = $row['race_website'];
if ($currMonth != $date->format('F')) :
{
echo '<h2>' . $date->format('F') . '</h2><br>';
$currMonth = $date->format('F');
}
endif;
echo '<ul>';
echo '<li><h2>' . $row['race_name'] . '</h2></li>';
echo '<li>Date ' . $date->format('F d, Y') . '</li>';
echo '<li>Distance ' . $row['race_distance'] . '</li>';
echo '<li>Vertical ' . $row['race_vertical'] . '</li>';
echo '<li>URL <a href=' . $website_url . '> ' . $website_url . ' </a></li>';
echo '<li>' . $row['race_description'] . '</li>';
echo '</ul>';
}
endforeach;
?>
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.