回答編集履歴
2
エラー修正
answer
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
'meta_query' => array(
|
9
9
|
'relation' => 'AND',
|
10
10
|
array(
|
11
|
-
'key' => 'start' // フィールド名を指定
|
11
|
+
'key' => 'start', // フィールド名を指定
|
12
12
|
'value' => date('Y-m-d'),
|
13
13
|
'compare' => '<=',
|
14
14
|
'type' => 'DATE',
|
15
15
|
),
|
16
16
|
array(
|
17
|
-
'key' => 'end' // フィールド名を指定
|
17
|
+
'key' => 'end', // フィールド名を指定
|
18
18
|
'value' => date('Y-m-d'),
|
19
19
|
'compare' => '>=',
|
20
20
|
'type' => 'DATE',
|
1
追記
answer
CHANGED
@@ -34,4 +34,17 @@
|
|
34
34
|
'type' => 'DATE',
|
35
35
|
),
|
36
36
|
```
|
37
|
-
4月中ならこんな感じ。valueを動的にすれば自由自在です。
|
37
|
+
4月中ならこんな感じ。valueを動的にすれば自由自在です。
|
38
|
+
|
39
|
+
###【追記】値を動的にする
|
40
|
+
例えば来月
|
41
|
+
```PHP
|
42
|
+
$next_month_start = date('Y-m-d', strtotime('first day of next month', strtotime(date('Y-m-d'))));
|
43
|
+
$next_month_end = date('Y-m-d', strtotime('last day of next month', strtotime(date('Y-m-d'))));
|
44
|
+
echo $next_month_start; // 2018-05-01
|
45
|
+
echo $next_month_end; // 2018-05-31
|
46
|
+
```
|
47
|
+
[PHP: date - Manual ](http://php.net/manual/ja/function.date.php)
|
48
|
+
[PHP: strtotime - Manual ](http://php.net/manual/ja/function.strtotime.php)
|
49
|
+
使ってる関数はこの2つだけなのでマニュアルみていじってみてください。
|
50
|
+
`PHP 日付 来週`などのワードで検索しても沢山出てきます。
|