Home › Forums › Add-ons › Repeater Field › Repeater sorted by Date › Reply To: Repeater sorted by Date
Do you mind giving me any tips on formatting and code structure? I am kinda new to PHP and although this works I am not confident.
One other question I have is, can you recommend a way to approach a UI that would let a user jump to points on the page that are grouped into the same month? Back story is each repeater will have a name and date and now, since I can sort the list by date I was hoping to make it easier for the user to jump to the content for August.
<!-- repeater -->
<?php
$repeater = get_field('race_event');
foreach( $repeater as $key => $row )
{
$column_id[ $key ] = $row['race_date'];
}
array_multisort( $column_id, SORT_ASC, $repeater );
foreach( $repeater as $row ) :
{
echo '<li>' . $row['race_name'] . '</li>';
$date = DateTime::createFromFormat('Ymd', $row['race_date']);
echo '<li>' . $date->format('m-d-Y') . '</li>';
}
endforeach;
?>
<!-- /repeater -->
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.