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',

closed as off-topic by kaiser Oct 29 '14 at 1:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Solved - forgot to deactivate another plugin that was using the pre_get_posts hook - argh! – shanebp Dec 19 '13 at 1:21

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'

  • 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

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