回答編集履歴
1
反応無いから追記
test
CHANGED
@@ -1,3 +1,123 @@
|
|
1
|
-
`
|
1
|
+
`save_post`を使ったらどうでしょうか。
|
2
2
|
|
3
3
|
[https://codex.wordpress.org/Plugin_API/Action_Reference/save_post](https://codex.wordpress.org/Plugin_API/Action_Reference/save_post)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
追記
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
無視?
|
12
|
+
|
13
|
+
何か反応あってもよくない?
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
`get_field`やとDBに保存したものしか取れんのが原因。
|
18
|
+
|
19
|
+
だからこう。
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
$cal_fields = get_field("switch", $post->ID);
|
24
|
+
|
25
|
+
↓
|
26
|
+
|
27
|
+
$cal_fields = $_POST['fields']['フィールドキー'];
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
これでもええんちゃうかと思うけど?
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
function makes_json( $post_id, $post, $update ) {
|
38
|
+
|
39
|
+
if (function_exists('xdebug_disable')) {
|
40
|
+
|
41
|
+
xdebug_disable();
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
if( $post->post_status === 'publish' ) {
|
46
|
+
|
47
|
+
// Get ALL Posts
|
48
|
+
|
49
|
+
$args = array(
|
50
|
+
|
51
|
+
'numberposts' => -1,
|
52
|
+
|
53
|
+
'orderby' => 'post_date',
|
54
|
+
|
55
|
+
'order' => 'DESC',
|
56
|
+
|
57
|
+
);
|
58
|
+
|
59
|
+
$posts = get_posts($args);
|
60
|
+
|
61
|
+
$homeUrl = 'http:test.jp/static_directory';
|
62
|
+
|
63
|
+
if (count($posts) == 0) { return; }
|
64
|
+
|
65
|
+
foreach ($posts as $post) {
|
66
|
+
|
67
|
+
$cal_fields = get_field("switch", $post->ID);
|
68
|
+
|
69
|
+
$output_json[date('Ym', strtotime($post->post_date))][] = array(
|
70
|
+
|
71
|
+
'title' => $post->post_title,
|
72
|
+
|
73
|
+
'start' => $post->post_date,
|
74
|
+
|
75
|
+
'url' => $homeUrl . '/archives/' . $post->ID,
|
76
|
+
|
77
|
+
'value' => $cal_fields,
|
78
|
+
|
79
|
+
);
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// Get Upload Directory
|
86
|
+
|
87
|
+
$upload_dir = wp_upload_dir();
|
88
|
+
|
89
|
+
$upload_dir = $upload_dir['basedir'].'/json';
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
// Create Directory
|
94
|
+
|
95
|
+
if (file_exists($upload_dir) == FALSE) {
|
96
|
+
|
97
|
+
mkdir($upload_dir, 0777);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
// Delete All JSON Files
|
104
|
+
|
105
|
+
array_map('unlink', glob($upload_dir.'/*.json'));
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
// Create JSON Files
|
110
|
+
|
111
|
+
foreach ($output_json as $key => $value) {
|
112
|
+
|
113
|
+
file_put_contents($upload_dir . '/'.$key.'.json', json_encode($value));
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
add_action('save_post', 'makes_json', 99, 3);
|
122
|
+
|
123
|
+
```
|