How to List Events by Year and Month Using Advanced Custom Fields?

This should get you started:

<?php

$the_query = new WP_Query( array(
    'post_type'   => 'kalender_item',
    'post_status' => 'publish',
    'meta_key'    => 'kalender_item_datum',
    '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(), 'kalender_item_datum', 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;

?>

Leave a Comment