Skip to content

Instantly share code, notes, and snippets.

@ferourives
Last active July 14, 2022 03:38
Show Gist options
  • Select an option

  • Save ferourives/c96c470d5b46f7e33f1d71768eddf263 to your computer and use it in GitHub Desktop.

Select an option

Save ferourives/c96c470d5b46f7e33f1d71768eddf263 to your computer and use it in GitHub Desktop.
List Events by Year and Month Using ACF
<?php
$the_query = new WP_Query( array(
'post_type' => 'calender_item',
'post_status' => 'publish',
'meta_key' => 'calender_item_date',
'orderby' => 'meta_value'
) );
# This will hold what group we're in
$current_header = '';
# The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
# get the datum for this post
$temp_date = get_post_meta( get_the_ID(), 'calender_item_date', true );
# If they aren't the same, we'll start a new group, which for now
# just means setting a new heading
if ( $temp_date != $current_header ) {
$current_header = $temp_date;
echo "<h2>$current_header</h2>";
}
# ... do normal loop stuff here
endwhile;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment