カスタムフィールドならmeta_query
パラメータで指定します。
参考:関数リファレンス/WP Query - WordPress Codex 日本語版
例えば「開催期間中」ならこう
PHP
1$args = array(
2 'meta_query' => array(
3 'relation' => 'AND',
4 array(
5 'key' => 'start', // フィールド名を指定
6 'value' => date('Y-m-d'),
7 'compare' => '<=',
8 'type' => 'DATE',
9 ),
10 array(
11 'key' => 'end', // フィールド名を指定
12 'value' => date('Y-m-d'),
13 'compare' => '>=',
14 'type' => 'DATE',
15 ),
16 ),
17);
18$myposts = get_posts($args);
「今週」「今月」などはcompareにBETWEENを渡せば2つのvalue(配列で指定)の間にあるものを取得できたりもします
PHP
1array(
2 'key' => 'start',
3 'value' => array('2018-04-01', '2018-04-30'),
4 'compare' => 'BETWEEN',
5 'type' => 'DATE',
6),
4月中ならこんな感じ。valueを動的にすれば自由自在です。
###【追記】値を動的にする
例えば来月
PHP
1$next_month_start = date('Y-m-d', strtotime('first day of next month', strtotime(date('Y-m-d'))));
2$next_month_end = date('Y-m-d', strtotime('last day of next month', strtotime(date('Y-m-d'))));
3echo $next_month_start; // 2018-05-01
4echo $next_month_end; // 2018-05-31
PHP: date - Manual
PHP: strtotime - Manual
使ってる関数はこの2つだけなのでマニュアルみていじってみてください。
PHP 日付 来週
などのワードで検索しても沢山出てきます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/04 15:57
2018/04/04 16:05
2018/04/04 16:20
2018/04/04 16:43
2018/04/04 17:49
退会済みユーザー
2018/04/05 01:40
退会済みユーザー
2018/04/05 01:43
2018/04/05 14:05