wordpress order posts by meta_value date in DESC order

wordpress order posts by meta_value date in DESC order



I am trying to sort a query to display posts in order of a meta_key value. The value is stored like so: 2018-Mar-23.


2018-Mar-23



I would like to display posts with a date that is after today, with the closest date for example 2018-Aug-30 being shown first, and the furthest date away 2020-Aug-30 to show last.


2018-Aug-30


2020-Aug-30



I have put a query together, which still mixes all dates up. Here is what i have:


$args = array(
'posts_per_page' => -1,
'post_type' => 'games' ,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'post_parent' => 0,
'meta_query' => array(
array(
'key' => 'releasedate',
'value' => date("Y-M-d"),
'type' => 'DATE',
'compare' => 'BETWEEN',
)
)
);



For some reason i can only get this query to work using the compare method "BETWEEN". Using ">" which i would expect to use, returns no results.


"BETWEEN"


">"



Any ideas?



Thanks





Can you try 'orderby' => 'meta_value', and compare' => '>',
– Sudharshan Nair
Aug 29 at 13:05


'orderby' => 'meta_value',


compare' => '>',




1 Answer
1



Can you try this


$args = array(
'posts_per_page' => -1,
'post_type' => 'games' ,
'orderby' => 'meta_value',
'order' => 'ASC',
'post_parent' => 0,
'meta_key' => 'releasedate',
'meta_query' => array(
array(
'key' => 'releasedate',
'value' => date("Y-M-d"),
'type' => 'DATE',
'compare' => '>',
)
)
);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)