“query_posts”的排序问题WordPress 中的函数。按自定义字段排序不起作用
我正在使用 WordPress,其中有一个事件列表系统。我的帖子中有一个名为starting_time的自定义字段,它是unix时间戳。现在我想通过这个query_post命令缩短starting_time的所有帖子:
query_posts(array(
'post_type' => 'event',
'meta_key' => 'end_time',
'meta_compare' =>'>=',
'meta_value'=>time(),
'order_by' => 'start_date',
'order' => 'ASC'
));
但它不起作用。这是网站 http://citystir.com/events/。我在剩余时间之前回显了 unix 中的 start_time,以便您可以看到该值。而且我的分页也不起作用。可能是我在 query_post 命令中做错了什么。
I am working with wordpress where i have a event listing system. There is a custom field in my post called starting_time which is unix timestamp. Now i want to short all posts by starting_time by this query_post command:
query_posts(array(
'post_type' => 'event',
'meta_key' => 'end_time',
'meta_compare' =>'>=',
'meta_value'=>time(),
'order_by' => 'start_date',
'order' => 'ASC'
));
But it not working. Here is the site http://citystir.com/events/. I am echoing the start_time in unix before the time remaining so you can see the value. And also my pagination is not working. May be I did something wrong in the query_post command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要确保查询中使用了正确的 meta_key 名称。您说自定义字段名为 starting_time,但您在代码中将
order_by
设置为 start_date。ASC 的顺序似乎没问题,因为这将显示下一个事件。
You need to make sure that you have the correct meta_key name used in the query. You say that the custom field is called starting_time but you set
order_by
to start_date in your code.The order seems ok at ASC as this will show next up event.
问题出在 order_by 命令上:)它不是 order_by 而是 orderby。
The problem was with the order_by command :) it is not order_by but orderby.