I have wp query for posts. I'm ordering them by custom field "event_date". (The field format example is 09.08.2016). I'm extracting year and month from each post and adding it as div class, however i want to wrap all posts by parent div for each month. At frontend i want it to have like this:
<div id="082016">
<div class="post 082016"><?php the_title();?></div>
<div class="post 082016"><?php the_title();?></div>
<div class="post 082016"><?php the_title();?></div>
</div>
<div id="092016">
<div class="post 092016"><?php the_title();?></div>
<div class="post 092016"><?php the_title();?></div>
</div>
<div id="102016">
<div class="post 102016"><?php the_title();?></div>
<div class="post 102016"><?php the_title();?></div>
<div class="post 102016"><?php the_title();?></div>
</div>
And so on. Is it possible to wrap all posts to such parent div? How should i do it?
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$wpquery = new WP_Query($args); ?>
<?php while( $wpquery->have_posts() ): $wpquery->the_post(); ?>
<?php
$date = get_field('event_date');
$year = date('Y',strtotime($date));
$month = date('m',strtotime($date));
$day = date('d',strtotime($date));
?>
<div class="<?php echo $month; echo $year;?>">
<h1><?php the_title();?></h1>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
Many thanks for any help!