Filtro Ora personalizzata WP_Query su meta_value
Domanda
Il mio obiettivo è quello di mostrare solo i messaggi con orari di apertura dopo l'orario lavorativo, per un dato giorno. Così, ad esempio, Ho un post (personalizzato) con i seguenti meta_key e meta_value:
meta_key = 'lunedi, meta_value = '14: 00 - 22:00'
Le ore di lavoro sono fissati: '08: 00 - 18:00'
Mi piacerebbe aggiungere un filtro al mio WP_Query personalizzato. Solo, io sono sempre bloccato a definire una funzione.
Il mio ingresso logico (sicuramente non corretto e completo) per la funzione:
$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
Guida a una funzione è molto apprezzato.
Soluzione
È possibile utilizzare i query_posts WP al filtro sui tuoi valori personalizzati; Esempio ean:
query_posts('meta_key=my_type&meta_compare=<=&my_value=20&orderby=my_value');
if (have_posts()) :
while ( have_posts() ) : the_post();
Ma, penso che è necessario sostituire i valori di tempo per stringa leggibile, forse ne vale strotime, di avere lo stesso formato per la query.