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 have a custom post type which uses dates and i have my custom columns set up in the admin. I need to be able to do order by that column by default - i have tried this code which I found on the net but after playing with it for an hour i still couldn't make it work and it only seemed to want to sort by title; can anyone help me.


share|improve this question
up vote 1 down vote accepted

I had to do this on a program management system. this should do the trick.

add_filter( 'pre_get_posts', 'my_sort_posts_listing' );
function my_sort_posts_listing( $wp_query ) {
    if ( is_admin() && $wp_query->get( 'post_type' ) == 'my_post_type' ) {
        $wp_query->set( 'meta_key', '_my_date_meta' );
        $wp_query->set( 'orderby', 'meta_value' );
        $wp_query->set( 'order', 'DESC' );

    return $wp_query;

assuming your dates are stored like YYY-MM-DD

share|improve this answer
Worked perfectly thanks – byronyasgur Jan 12 '12 at 22:44

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.