0
votes

the query does not sort the right way. It should sort it by meta_value called event_date. (ASC or DESC, both not working)

I have 4 example dates.

2019-11-04
2019-10-31
2019-10-29
2019-10-28

They are also saved like this.

My query looks like:

$events = new WP_Query(array(
            'post_type' => $WP_Capone_Plugin->get_Capone_Events_post_type(),
            'post_status' => 'publish',
            'posts_per_page' => -1,
            'meta_key'         => 'event_date',
            'meta_type'        => 'DATETIME',
            'orderby'          => 'meta_value_datetime',
            'order' => 'DESC',
        ));

The result of this query is:

2019-11-04
2019-10-28
2019-10-29
2019-10-31

Tried a few other ways, but nothing is working the right way.

1
in what order do you want it exactly? - Darsh khakhkhar
Like this: 2019-11-04 2019-10-31 2019-10-29 2019-10-28 - yfain
Try "meta_value" instead of "meta_value_datetime" - Darsh khakhkhar
Not working with this change - yfain

1 Answers

0
votes

you should add this

'meta_key'=>'event_date',
'orderby'=>'meta_value_num',
'order'=>'DESC'