My goal is to only show posts with opening hours after business hours, for a given day. So, e.g. I have a (custom) post with following meta_key and meta_value:
meta_key = ‘monday, meta_value = ’14:00 – 22:00’
The business hours are fixed: ’08:00 – 18:00′
I’d like to add a filter to my custom wp_query. Only, I am getting stuck at defining a function.
My logic input (definitely not correct & complete) for the function:
$from_std = strtotime("08:00");
$to_std = strtotime("18:00");
$open = $my_meta['monday'];
list($from, $hyphen, $to) = explode(' ', $open);
$from_bus = strtotime($from);
$to_bus = strtotime($to);
if ($from_bus < $from_std) { $show = 1; } // before standard starting time - so SHOW
else {if ($to_bus > $to_std) { $show = 1; }} // after standard closing time - so SHOW
if (empty($from_bus)) { show = 0; } // $var is either 0, empty, or not set at all - so do NOT show
Help on a function is very much appreciated.
You can use the WP query_posts to filter about your custom values; ean example:
But, i think you must replace the time-values for readable string, maybe woth strotime, that you have the same format for the query.