Okay – I tried this again. ‘orderby’ => ‘meta_value_num’ solved the issue. As long as the date format for this field is set to YYYYMMDD
I have the same issue – also trying to order by a custom date field. So the code looks almost identical. I have orderby written correctly but still have this issue.
I’ve also tried ‘orderby’ => ‘meta_value’ and ‘orderby’ => ‘meta_value_num’ with no difference.
My args are:
$args = array(
‘post_type’ => array( $post_type ),
‘post_status’ => array( ‘publish’ ),
‘posts_per_page’ => -1,
‘tax_query’ => array(
array (
‘taxonomy’ => $taxonomy,
‘terms’ => $term_id,
)
),
‘meta_query’ => array(
array(
‘key’ => ‘date’,
‘compare’ => ‘>=’,
‘value’ => $date_now,
‘type’ => ‘DATETIME’
),
),
‘order’ => ‘DESC’,
‘orderby’ => ‘meta_value’,
‘meta_key’ => ‘date’,
‘meta_type’ => ‘DATETIME’,
);
I’d be grateful if you have any pointers 🙂