WordPress orderby meta_value not ordering properly

I have a custom post type called ‘events’ and I am to display the first 4 more recent events in event date order on the home page. I have got the events to show on the home page however the ordering doesn’t seem to be working (see below the example). It seems to be ordering in its own way.

$args = array('post_type' => 'events', 'meta_key' => 'event-date', 'orderby' => 'meta_value', 'order' => 'ASC', 'posts_per_page' => -1);
$events = new WP_Query( $args );

That is my code and here are the results (the dates) I get back.

Read More
16/04/2014
16/05/2014
19/03/2014
25/02/2014
27/02/2014
28/02/2014

As you can see, this is not ordering by ASC so what have I done wrong?!

Thanks in advance

Related posts

Leave a Reply

1 comment

  1. Try to use meta_value_num instead of meta_value in orderby parameter. Use following code:

    $args = array(
            'post_type'         => 'events', 
            'meta_key'          => 'event-date', 
            'orderby'           => 'meta_value_num', 
            'order'             => 'ASC', 
            'posts_per_page'    => -1
            );
    
    $events = new WP_Query( $args );