Home › Forums › General Issues › Order events by month › Reply To: Order events by month
This is the way I generally do this. You already have the posts ordered by date. What you need to do is loop through them and when the month changes, add a new heading, so you need to alter the loop a bit.
This is pretty basic, only showing the concept. It could get more complicated depending on what you want to do between the posts for each month.
$last_month = ''; // empty to start
while (have_posts()) {
the_post();
$this_month = ''; // calculate the month for this post
if ($this_month != $last_month) {
echo '<h2>',$this_month,'</h2>';
}
$last_month = $this_month;
// the rest of the output for your post goes here.
}
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.