Home › Forums › General Issues › List events by date › Reply To: List events by date
You could check to see if the date has changed from the last event displayed, and if it has, then you display the date; otherwise you just display the event.. something along the lines of:
// initialize the last displayed date.. since this is before the loop, we'll just make it an empty string
$lastDate = '';
while ($schedule_query->have_posts()) : $schedule_query->the_post(); ?>
<?php // now that we're in the loop, start outputting events ?>
<div class="screening">
<h2><strong><?php $date = DateTime::createFromFormat('Ymd', get_field('screening_date'));
// now that we have the event's date, see if it matches the last date displayed.. if not, we'll update $lastDate with the event's date and display it
if ($date != $lastDate) {
$lastDate = $date;
echo $date->format('F d, Y'); ?>, </strong></h2>
}
...
endwhile;
?>
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.