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' => '>'
)
)
If you only need it to work for today, you can use:
or alternatively
Some combination of
mktime()
andstrtotime()
should work.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.