Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to retrieve a custom post type and order it by a custom date stored in postmeta.

The custom date is a unix timestamp. The meta_query works correctly - it only retrieves posts with a custom date in the future.

But the orderby does not work - the order is still based on the post_date.

What am I missing?

   $today = date("m/d/Y");
   $today = strtotime( $today ); 

    query_posts( array(
        'post_type'      => 'custom_cpt',
        'orderby'    => 'meta_value',
        'meta_key'   => 'custom_date',
        'paged'          => $paged,
        'posts_per_page' => 5,

        'meta_query' => array(
                'key'       => 'custom_date',
                'value'     => $today,
                'compare'   => '>',
                'type'      => 'NUMERIC',
share|improve this question
Solved - forgot to deactivate another plugin that was using the pre_get_posts hook - argh! –  shanebp Dec 19 '13 at 1:21

1 Answer 1

For numeric data, the orderby key should have value as meta_value_num. Use WP_Query and change

'orderby' => 'meta_value'


'orderby' => 'meta_value_num'

share|improve this answer
Tried using WP_Query but the order is still using post_date. Also tried using 'meta_value_num' in query_posts. –  shanebp Dec 19 '13 at 1:12
Also tried using post__in, but still ordered by post_date. –  shanebp Dec 19 '13 at 1:15
Solved - the problem was being dumb, see above. Thanks for trying to help. –  shanebp Dec 19 '13 at 1:22

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.