I'm trying to display a list of upcoming football matches in order of kick off. The code I currently have lists the dates in the correct order but the posts ordering is incorrect.
<?php
$previews_new_loop = array(
'posts_per_page' => -1,
'post_type' => 'football_match',
'meta_key' => 'kick-off-date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
$wpquery = new WP_Query( $previews_new_loop );
$posts = $wpquery->get_posts();
$ordered_posts = array();
foreach ( $posts as $post ) {
$meta_value = get_post_meta( $post->ID, 'kick-off-date', true );
if ( !$meta_value ) {
continue;
}
$date = date( 'ddmmyyyy', strtotime( $meta_value ) );
$ordered_posts[$date][] = $post;
}
foreach ( $ordered_posts as $post_date => $posts ) {
foreach ( $posts as $post ):
endforeach;
}
'order' => 'ASC',);