How can group posts by month and year by a separate headline?
Example (output with this date format):
Dezmber 2014
– 4. Dez 2014
– 5. Dez 2014
I have a custom field (datepicker) “event_date”.
<?php
$the_query = new WP_Query( array(
'post_status' => 'publish',
'meta_key' => 'event_date',
'orderby' => 'meta_value'
) );
$current_header="";
while ( $the_query->have_posts() ) :
$the_query->the_post();
$temp_date = get_post_meta( get_the_ID(), 'event_date', true );
if ( $temp_date != $current_header ) {
$current_header = $temp_date;
echo "<div class="sub_category_name_wrapper"><h5>$current_header</h5></div>";
}
?>
<div class="event_content_wrapper">
<ul>
<li>
<span><?php the_field('event_date'); ?></span> <span><?php the_field('event_region'); ?></span>
<h4><?php the_title(); ?></h4>
<br>
<?php the_excerpt(); ?>
<a class="content_button" href="https://wordpress.stackexchange.com/questions/174517/<?php the_permalink(); ?>">mehr</a>
</li>
</ul>
</div>
<?php endwhile;
?>