Question

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.

Was it helpful?

Solution

You can use the WP query_posts to filter about your custom values; ean example:

query_posts('meta_key=my_type&meta_compare=<=&my_value=20&orderby=my_value');
if (have_posts()) :
while ( have_posts() ) : the_post();

But, i think you must replace the time-values for readable string, maybe woth strotime, that you have the same format for the query.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top