Apologies if this is a duplicate of my original post…it keeps getting deleted if you edit it more than once?
Hey guys, I have done a bunch of searching and can’t seem to find a resolution particular to what I’m looking to do. Here’s what’s up:
I created an event custom post type. Within each of those posts, are repeaters which allow the person to select multiple date and times. What I would like to do, and I’m not sure it’s possible the way I’m thinking, is group the events that have the same dates, by date.
Something like this:
And so fourth and so on….
While I’ve come across similar issues with potential resolutions, I’ve got nothing to work. Here’s how I’m handling my code:
Outside the while loop:
$current_header = '';
Inside the while loop:
$date_count = count(get_field('dates_times'));
// Group events
for ($i = 0; $i < $date_count; $i++) :
// Get repeater fields
$dates = 'dates_times_' . $i . '_date';
// Snatch up the postmeta
$temp_date = get_post_meta( get_the_ID(), $dates, true );
// Convert Date
$date = DateTime::createFromFormat('Ymd', $temp_date);
if ( is_object($date) ) $day = $date->format('l - F, j');
// Group by day
if ( $day != $current_header ) :
$current_header = $day;
echo '<h2 class="medium-12 cell">' . $day . '</h2>';
// REST OF POST CODE HERE
And so on…. They’re not being grouped as expected. I assume the for loop is throwing them off. So any ideas or suggestions here would be greatly appreciated.