Hi all,
I would like to be able to sort them by date and compare them to the current date to show that those to come.
Does anyone have a solution for it?
<?php
$post_object = get_field('agenda');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<?php if ( have_rows( 'list_of_date' ) ) : ?>
<?php while ( have_rows( 'liste_of_date' ) ) : the_row(); ?>
<ul class="agenda">
<li><?php the_sub_field( 'date_start' ); ?></li>
<li><?php the_sub_field( 'date_end' ); ?></li>
<?php } ?>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Hi @ikazi
Something like the code below should do the trick…
In it, I loop through the repeater, and add only non-expired dates to an array..
.. then I sort it… then… you can loop through the result set. Give it a try and let me know 🙂
$repeater = get_field('list_of_date');
foreach( $repeater as $key => $row ) {
if ( strtotime( $row['date_end'] ) > strtotime( date() ) ) { // not expired, add to array
$column_id[ $key ] = $row['date_start'];
}
}
array_multisort( $column_id, SORT_ASC, $repeater ); // sort the array
foreach( $repeater as $row ) {
// loop through the array
}
Resource: https://support.advancedcustomfields.com/forums/topic/repeater-sorted-by-date/