如何修改此查询,以便开始/结束日期按天而不是精确时间?
我使用下面的查询来获取基于使用 UNIX 时间戳的开始日期和结束日期的帖子。
目前,仅当开始时间晚于今天的时间时才返回结果。例如,如果时间为下午 5:00,开始日期为下午 6:00,则不会选取它。我希望将今天的任何时间(从昨晚午夜到今晚午夜)视为开始日期。
有人可以告诉我如何更新我的代码以使其正常工作吗?
$current_time
等于 1305132894
,即今天美国东部时间 5:54。
'meta_query' => array(
array(
'key' => 'start_date',
'value' => $current_time,
'compare' => '<'
),
array(
'key' => 'end_date',
'value' => $current_time,
'compare' => '>'
)
)
I'm using the query below to get posts based on the start and end dates which use the UNIX timestamp.
Currently, it's only returning results if the start time occurred after today's time. For example, if it's 5:00 PM and the start date is 6:00 PM, it won't pick it up. I would like it to consider anytime during today (from midnight last night to midnight tonight) as being the start date.
Can someone tell me how to update my code to get this to work?
$current_time
is equal to 1305132894
, which is 5:54 EST today.
'meta_query' => array(
array(
'key' => 'start_date',
'value' => $current_time,
'compare' => '<'
),
array(
'key' => 'end_date',
'value' => $current_time,
'compare' => '>'
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只需要它今天工作,您可以使用:
或者
mktime()
的某种组合 和strtotime()
应该可以工作。If you only need it to work for today, you can use:
or alternatively
Some combination of
mktime()
andstrtotime()
should work.考虑您的示例:
$current_time = 1305132894
这应该可以回答您的问题:
因此,将 $current time 替换为 $date_midnight ,您将在今天从昨晚午夜开始的任何时间。
Considering your example:
$current_time = 1305132894
This should answer your question:
So replace $current time by $date_midnight and you'll have anytime during today from midnight last night.