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 have read countless posts on ordering data by numeric value ( as opposed to string - it i have a numeric meta value and it gets ordered like this 1 11 12 2 233 etc as opposed to the way i want it

I am using WP_Query have tried using meta_query => 'NUMERIC' but i'm not sure if that's what it's actually supposed to do

eg

$args =  array(
    'meta_query' => array(
            array(
                  'type' => 'NUMERIC'
            )
    ),
    'orderby' => 'meta_value',
    'meta_key' => '_date',
    'post_type' => 'events',
    'posts_per_page' => 5,
    'order' => 'ASC'

);

share|improve this question

1 Answer 1

up vote 3 down vote accepted

you need to use

'orderby' => 'meta_value_num', 

also if you are ordering dates, the best advice is to put them in an easy to order way such as 2012-12-31

share|improve this answer
    
Thanks, that worked fine. Actually I have the day, month and year in separate meta values, which now presents the problem that i cant seemingly order by multiple meta values which was what I had planned. –  byronyasgur Jan 12 '12 at 2:46

Your Answer

 
discard

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.