Here’s my problem , I have a custom post type “Emissions” , and i wrote a query to get all posts where the day field is equal to today , and where the field hour is inferior to current time , so that the query is for displaying the “Upcoming” ,
up to that , i’m good , but when it comes to ordering the posts by the field hour , in an ascending order , the output isn’t ordered at all , is there any problem with my code ?
$args = array(
'posts_per_page' =>3,
'post_type' => 'emissions',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'jour',
'value' => $lyoum,
'compare' => '='
),
array(
'key' => 'horaire',
'value' => $douka,
'compare' => '<',
'order_by' => 'meta_value_num',
'order' => 'DESC',
)
));
if anyone wants to help , that would be great ,
ps : variables are
$lyoum = $today , datetime getting the current day,
$douka = $now ,datetime getting the current time,
Thanks in advance.
Your order parameters are misplaced in the
WP_Meta_Query
args. They instead belong in the mainWP_Query
args. You also need to specify the meta key to order by.