WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to sort the posts (in the edit screen (wp-admin/edit.php)) by meta value corresponding to an event date but I can't get it to work properly...

For example, ASC returns:


and DESC returns:


I'm using the following functions to create the sortable custom columns:

function event_date_column_display( $name ) {
    global $post;
    switch ($name) {
        case 'event-date':
            $pid = $post->ID;
            $event_date = get_post_meta($pid, '_event_date', TRUE);

            if ($event_date) {
                echo $event_date;

function event_date_column_register_sortable( $columns ) {
    $columns['event-date'] = 'event-date';  
    return $columns;

Any hint on how to fix this?

share|improve this question

Is it not an option to insert the sorting directly to the WP_Query class? It has all the parameters for handling this kind of situation http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

If you want to do that in the code, you can first validate all the dates, then convert them to the standard ISO(yyyy-mm-dd) format & then use the standard php functions to sort them like sort, ksort, (usort combined with strcmp) or any other depending on your data

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.