Meta_ValueのカスタムWP_QUERYタイムフィルター
質問
私の目標は、特定の日の営業時間後の営業時間でのみ投稿を表示することです。したがって、たとえば、Meta_KeyとMeta_Valueを次のようにする(カスタム)投稿があります。
Meta_key = '月曜日、Meta_Value = '14:00-22:00'
営業時間は固定されています:'08:00-18:00 '
カスタムwp_queryにフィルターを追加したいと思います。のみ、私は関数の定義にとどまっています。
関数のための私のロジック入力(間違いなく正しいと完全ではありません):
$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
関数のヘルプは大歓迎です。
解決
WP Query_Postsを使用して、カスタム値についてフィルタリングできます。例:
query_posts('meta_key=my_type&meta_compare=<=&my_value=20&orderby=my_value');
if (have_posts()) :
while ( have_posts() ) : the_post();
しかし、クエリに同じ形式があるという読みやすい文字列、おそらくWoth Strotimeの時間値を置き換える必要があると思います。
所属していません wordpress.stackexchange