WordPress 自定义内容类型日期字段
嘿,我正在尝试构建最直观的事件帖子类型。我想知道是否有一个核心方法可以打印和捕获日期字段的内容 - 特别是年/月/日,我不需要小时/分钟。我还需要能够按日期对条目进行排序以便稍后打印 - 例如,我需要一月份的所有事件。可以节省我格式化字段,然后手动解析和保存它们的东西。
欢迎任何想法!预先感谢您的宝贵时间。
Hey, I'm trying to build the most intuitive possible Event post type. I'm wondering if there's a core method to both print out and capture the contents of a date field - specifically year/month/day, I don't need hours/minutes. I also need to be able to sort entries by date to print out later - for instance, I need all of the events from January. Something that can save me formatting the fields, and then parsing and saving them manually.
Any ideas are welcomed! Thanks in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对此没有坚如磐石的 WP 核心解决方案,但我创建的系统由以下部分组成:
SQL
CONCAT
用于将日期字段与CURDATE
进行比较,等等PHP
strToTime
从数据库获取日期一般来说,如果您以 UNIX 时间格式将日期保存到数据库中,则很容易在 SQL 查询和 PHP 输出中使用。
There was no rock solid WP core solution to this, but the system I created is composed of:
SQL
CONCAT
to compare a date field toCURDATE
, etc.PHP
strToTime
to get the date back from the databaseGenerally speaking, if you save your date to the DB in UNIX time format it's easy to work with in SQL queries and in your PHP output.