First of all I don’t think you should use your custom query_posts in here. WordPress already queries posts on archive pages, so it’s waste of time to query them one more time. You should be using pre_get_posts
filter.
function my_pre_get_posts($query) {
if (!is_admin() && is_main_query() '<YOUR_POST_TYPE>' === $query->query_vars('post_type')
&& $query->is_archive()) {
$query->set('orderby','meta_value');
$query->set('meta_key', '<YOUR_POST_TYPE>'); //formatted YYYYMMDD
$query->set('ignore_sticky_posts', true);
}
return $query;
}
add_filter('pre_get_posts','my_pre_get_posts');
When your posts are selected, you can split them by month doing it manually in your loop. Somthing like this should solve your problem:
$prev_month="";
while ( have_posts() ):
the_post();
$post_custom_date = strtotime(get_post_meta($post->ID, 'Deadline', true)); // this line may need to be changed - it depends on the format you choosed to store dates in deadline meta value
$current_month = date('F Y', $post_custom_date );
if ( $current_month != $prev_month ) {
echo '<h2>'. $current_month .'</h2>';
$prev_month = $current_month;
// output your post/event
endwhile;
It’s not tested so it can be a little bit buggy, but the idea behind this solution should be clear.