通过自定义元键订购 WP 帖子 [英] Ordering WP Posts by Custom Meta Key

查看:33
本文介绍了通过自定义元键订购 WP 帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 WordPress 自定义帖子类型,以便能够创建事件、选择事件的日期并在前端显示日期.

I created a WordPress custom post type to be able to create events, select the event's date, and display the date on the frontend.

我在 WP 数据库的 postmeta 中添加了一个新的 meta_key 以将事件的日期存储在 UNIX 时间戳中.

I added a new meta_key in the postmeta of WP's database to store the event's date in a UNIX timestamp.

我在创建新的 WP 查询以在我的网站上输出我的事件时没有遇到任何问题,但我试图弄清楚如何通过数据库中的 UNIX 时间戳来组织事件,而不是通过 WordPress 创建事件的日期.

I've had no trouble creating a new WP query to output my events on my site but I am trying to figure out how to organize the events by their UNIX timestamp in the database, not by the date that WordPress created the events.

我似乎无法理解这件事..有什么建议吗?

I can't seem to wrap my head around the thing.. any advice?

推荐答案

相信你的查询可以有

'orderby' => 'meta_value_num',
'meta_key' => 'event_timestamp' //or whatever your meta_key is

你可以在这里阅读:http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

这篇关于通过自定义元键订购 WP 帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆