Home › Forums › Add-ons › Repeater Field › Sort repeater field by date sub field › Reply To: Sort repeater field by date sub field
Thanks James, that was really helpful! I think I must have missed out the $column_id and also not calling the $row properly. I thought I’d add in my finished code in case it helps someone:
<?php
$repeater = get_field('company_rates');
$column_id = array();
foreach( $repeater as $key => $row ) {
$thedate = $row['company_date'];
$column_id[ $key ] = strtotime($thedate);
}
array_multisort( $column_id, SORT_DESC, $repeater );
foreach( $repeater as $row ){
$date = DateTime::createFromFormat('Ymd', $row['company_date']);
echo ' <article class="item">
<span class="metaDate">'.$date->format('d / M / Y').'</span>';
// This is pulling in a (company) relationship field I have
$posts = $row['company'];
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
echo '<h2><a href="'.get_permalink().'">'.get_the_title().'</a></h2>';
endforeach;
wp_reset_postdata();
endif;
echo ' <span class="bigPecent">'.$row['percentage_number'].'%</span>
</article>';
}
?>
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.