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'
);
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0