WordPress 查询帖子,从自定义字段日期获取当月的所有帖子
我在 wp 3.1 中有一个事件自定义帖子类型,我正在使用以下 query_posts:
<?php query_posts('post_type=event&meta_key=event_date&orderby=meta_value&order=ASC'); ?>
如您所见,我按自定义帖子类型日期排序。我的问题是我只想列出当月的事件。查询帖子提供了monthnum,但是我需要将monthnum传递到查询中,我不知道这怎么可能。日期格式为 YYYY-mm-dd
I have an events custom post type in wp 3.1 I am using the following query_posts:
<?php query_posts('post_type=event&meta_key=event_date&orderby=meta_value&order=ASC'); ?>
As you can see I am ordering by the custom post type date. My issue is that I want to list only the events for the current month. Query posts offers monthnum but then I need to pass the monthnum into the query and I have no idea how that would even be possible. The date format is YYYY-mm-dd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们要获取帖子的发布日期,它将类似于:
但是要从元值中获取日期,您尝试过吗?:
您可以使用以下方式获取当月的第一天:
否则,我会尝试像您一样检索所有帖子,然后使用每个元值创建日期对象,并将其月份和年份与当前进行比较。
If we were to get the date of the publication of the post it would be something like:
But to get the date from the meta values, have you tried?:
You can get the first day of the current month with something like:
Otherwise, I would try by retrieving all the posts as you were doing and then make date objects with each meta value and compare its month and year with current.