简体   繁体   English

Wordpress / Acf查询由自定义字段发布,并由另一个字段对其进行排序

[英]Wordpress / Acf Query Posts by a custom field and order them by another

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" , 这是我的问题,我有一个自定义的帖子类型“Emissions”,我写了一个查询来获取所有帖子,其中day字段等于今天,并且字段小时不如当前时间,以便查询用于显示“即将来临”,

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 ps:变量是

$lyoum = $today , datetime getting the current day, $ lyoum = $ today,datetime到达当天,

$douka = $now ,datetime getting the current time, $ douka = $ now,datetime获取当前时间,

Thanks in advance. 提前致谢。

Your order parameters are misplaced in the WP_Meta_Query args. 您的订单参数在WP_Meta_Query args中放错了WP_Meta_Query They instead belong in the main WP_Query args. 它们属于主要的WP_Query args。 You also need to specify the meta key to order by. 您还需要指定要按顺序排列的元键。

. . . 
'post_type'     => 'emissions',
'meta_key'      => 'horaire' // specify which key to order by.
'orderby'       => 'meta_value_num', // move from WP_Meta_Query.
'order'         => 'DESC', // same as above.
'meta_query'    => array(
. . . 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM