I've been using a CPT named "session" that has some date fields. Those date fields are stored via the CMB2 plugin with something like this :
$cmb->add_field( array(
'name' => __('Begin :', 'cmb2'),
'id' => $prefix . 'session_datebegin',
'desc' => __( 'Beginning date of the session', 'cmb2' ),
'type' => 'text_date',
'date_format' => 'd-m-Y'
) );
Now I want to display the sessions, ordered by the "closest" date. Here are the args used in my WP query :
$args = array(
'post_type' => 'session',
'posts_per_page' => -1,
'meta_key' => 'session_datebegin',
'orderby' => 'session_datebegin',
'order' => 'ASC'
);
Let's say I have 3 dates : 22-04-2016, 20-04-2016 and 05-05-2016. The previous query gives : 05-05-2016, 20-04-2016, 22-04-2016. As you guessed, using "DESC" instead of "ASC" returned : 22-04-2016, 20-04-2016, 05-05-2016.
The date settings for my WP install are custom ones, under this form : d-m-Y.
I just can't figure out where the problem takes place : for "may", even there is a confusion somewhere with the US date format, 05-05-2016 will always be equal to 05-05-2016, won't it ?!
How can I make a proper sort with this date format ? Thanks