WP_Query 和 acf 日期字段排序不正确
我试图只看到与今天之后或相等的帖子,然后对ASC进行排序,我的日期字段输出YMD,第一部分(仅在当今或等于今天的帖子)工作,但排序却没有。
$today = date ('Ymd');
$args = array(
'post_type' => 'diensten',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'datum_dienst',
'value' => $today,
'compare' => '>='
)
),
'meta_key' => 'datum_dienst',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
$loop = new WP_Query( $args );
I am trying to only see posts after or equal to today and sort ASC, my date field outputs Ymd, the first part (only see posts after or equal to today) works but the sorting does not.
$today = date ('Ymd');
$args = array(
'post_type' => 'diensten',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'datum_dienst',
'value' => $today,
'compare' => '>='
)
),
'meta_key' => 'datum_dienst',
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
$loop = new WP_Query( $args );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于面临同样问题的少数人,这是我非常具体的解决方案。
如果您安装了 WordPress 插件 Post Types Order,它将覆盖您的订单查询,我卸载了它,一切都神奇地工作了!
For the few people facing the same problem, here is my very specific solution.
If you have the wordpress plugin Post Types Order installed it will override your order query, i uninstalled it and everything magically worked!
如果您在按日期排序数据时遇到问题,可以添加
'meta_type' =>; 'DATE'
设置元类型。如果您不使用
meta_query
而只是想对数据进行排序,也可以解决该问题。所以它将是:
更多信息:https://developer.wordpress.org/reference/classes /wp_query/
If you are having trouble with data getting sort by dates, you can add
'meta_type' => 'DATE'
to set the meta type.Also solves the issue if you are not using a
meta_query
but just want to sort the data.So it will be:
More info: https://developer.wordpress.org/reference/classes/wp_query/