Home › Forums › Add-ons › Repeater Field › Date picker excluding past repeater fields
Hi, hope someone can help on this.
I’m using a date picker in a repeater to show events and want to not show events that are before the current date.
I’ve got the date to show by using the CreateFromFormat within the repeater, but need to figure out an if statement that excludes past entries.
Everything I’ve found refers to excluding dates from a post loop and not in a repeater, so a little stumped. This is my code for showing the date.
<?php if( have_rows('academy_dates') ): ?>
<?php while( have_rows('academy_dates') ): the_row();
// vars
$datetime = DateTime::createFromFormat('j F, y', get_sub_field('date'));
$date_day = $datetime->format('j');
$date_month = $datetime->format('F');
$date_year = $datetime->format('y');
$month = get_sub_field('month');
$location = get_sub_field('location');
$title = get_sub_field('title');
$content = get_sub_field('academy_description');
?>
<div class="academy-date">
<div class="academy-date-inner">
<div class="date"><?php echo $date_day; ?></div>
<div class="month"><?php echo $date_month; ?> '<?php echo $date_year; ?></div>
<div class="divider-line"></div>
<div class="academy-title"><?php echo $title; ?></div>
<div class="location"><i class="fas fa-map-marker-alt"></i> <?php echo $location; ?></div>
<div class="description"><?php echo $content; ?></div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Hope someone can help.
Thanks
Aaron
Is this a date or a date/time field?
// date field
if (have_rows('academy_dates')) {
while (have_rows('academy_dates')) {
the_row();
$raw_date = get_sub_field('date', false);
$today = date('Ymd');
if ($raw_date < $today) {
// skip it
continue;
}
// the rest of your code here....
} // end while
} // end if
// time field
if (have_rows('academy_dates')) {
while (have_rows('academy_dates')) {
the_row();
$raw_date = date('Ymd', get_sub_field('date', false);)
$today = date('Ymd');
if ($raw_date < $today) {
// skip it
continue;
}
// the rest of your code here....
} // end while
} // end if
Hi John.
It’s a date picker.
Thanks for the example, will give it a go now!
Thank you.
Aaron
Thank you John, it worked perfectly!!
Have a fantastic weekend.
The topic ‘Date picker excluding past repeater fields’ is closed to new replies.
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.