Home › Forums › General Issues › Helping event posts displaying by month › Reply To: Helping event posts displaying by month
Hi @ikazi
You need to save the month in a temporary variable and then check if the current month is the same with the one in the temporary variable or not. Maybe something like this:
<?php if( $the_query->have_posts() ): ?>
<?php $current_month = ""; ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li class="list-representations">
//month display tag
<div class="list-separator-month">
<h2>
<?php
$dateformatstring = "F Y";
$unixtimestamp = strtotime(get_field('date_start'));
$pretty_month = date_i18n($dateformatstring, $unixtimestamp);
if ($current_month != $pretty_month){
echo $pretty_month;
$current_month = $pretty_month;
}
?>
</h2>
</div>
<article>
Hope this helps.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.