回答編集履歴

1

dad

2021/11/24 23:19

投稿

kazOh
kazOh

スコア16

test CHANGED
@@ -1,239 +1,3 @@
1
- function dess_post_meta_box() {
1
+ ssssssssssssssssssssssss
2
2
 
3
-
4
-
5
- add_meta_box(
6
-
7
-
8
-
9
- 'dess_post_settings',
10
-
11
-
12
-
13
- __('Post Settings',''),
14
-
15
-
16
-
17
- //_notice_meta_box_callbackに注目してください。メタボックスにフォームフィールドを表示する関数
18
-
19
- 'dess_post_meta_box_callback',
20
-
21
-
22
-
23
- 'post'
24
-
25
-
26
-
27
- );
28
-
29
-
30
-
31
- }
32
-
33
-
34
-
35
- add_action( 'add_meta_boxes', 'dess_post_meta_box' );
36
-
37
-
38
-
39
- //「投稿」にメタボックスを追加する add_meta_boxes s 複数形
40
-
41
-
42
-
43
- function dess_post_meta_box_callback( $post ) {
44
-
45
-
46
-
47
- wp_nonce_field( 'dess_post_save_meta_box_data', 'dess_post_meta_box_nonce' );
48
-
49
-
50
-
51
- //slider in slider post id in meta box
52
-
53
- $show_in_slider = get_post_meta( $post->ID, 'show_in_slider', true );
54
-
55
-
56
-
57
- //show in homepage post id in meta box
58
-
59
- $show_in_homepage = get_post_meta( $post->ID, 'ex_show_in_homepage', true );
60
-
61
-
62
-
63
- //page_featured_type post id
64
-
65
- $type = get_post_meta( $post->ID, 'page_featured_type', true );
66
-
67
-
68
-
69
- //投稿編集画面のメタボックスhtml
70
-
71
-
72
-
73
- echo '<p><label for="show_in_slider">'.__('Show in Slider','').': </label>';
74
-
75
-
76
-
77
- //slider in slider post id from meta box
78
-
79
- echo '<input type="checkbox" id="show_in_slider" name="show_in_slider" value="Yes" '.($show_in_slider == 'Yes' ? 'checked' : '' ).' /></p>';
80
-
81
-
82
-
83
- echo '<p><label for="show_in_homepage">Show in Homepage: </label>';
84
-
85
-
86
-
87
- //show in homepage post id from meta box
88
-
89
- echo '<input type="checkbox" id="show_in_homepage" name="ex_show_in_homepage" value="Yes" '.($show_in_homepage == 'Yes' ? 'checked' : '' ).' /></p>';
90
-
91
-
92
-
93
- echo '<p><label for="video_type">'.__('Featured Type','').': </label><br/>';
94
-
95
-
96
-
97
- echo '<select id="video_type" name="dess_post[page_featured_type]"><option value="">Image</option><option value="youtube" '.($type == 'youtube' ? 'selected="selected"' : '').'>Youtube</option><option value="vimeo" '.($type == 'vimeo' ? 'selected="selected"' : '').'>Vimeo</option></select></p>';
98
-
99
-
100
-
101
- echo '<p><label for="video_id">'.__('Video ID','').': </label><br/>';
102
-
103
-
104
-
105
- echo '<input type="text" id="video_id" name="dess_post[page_video_id]" value="'.get_post_meta( $post->ID, 'page_video_id', true ).'" /></p>';
106
-
107
-
108
-
109
- }
110
-
111
-
112
-
113
- function dess_post_save_meta_box_data( $post_id ) {
114
-
115
-
116
-
117
- if ( ! isset( $_POST['dess_post_meta_box_nonce'] ) ) {
118
-
119
-
120
-
121
- return;
122
-
123
-
124
-
125
- }
126
-
127
-
128
-
129
- if ( ! wp_verify_nonce( $_POST['dess_post_meta_box_nonce'], 'dess_post_save_meta_box_data' ) ) {
130
-
131
-
132
-
133
- return;
134
-
135
-
136
-
137
- }
138
-
139
-
140
-
141
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
142
-
143
-
144
-
145
- return;
146
-
147
-
148
-
149
- }
150
-
151
-
152
-
153
- if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
154
-
155
-
156
-
157
- if ( ! current_user_can( 'edit_page', $post_id ) ) {
158
-
159
-
160
-
161
- return;
162
-
163
-
164
-
165
- }
166
-
167
-
168
-
169
- } else {
170
-
171
-
172
-
173
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
174
-
175
-
176
-
177
- return;
178
-
179
-
180
-
181
- }
182
-
183
-
184
-
185
- }
186
-
187
-
188
-
189
- $show_in_slider = sanitize_text_field( $_POST['show_in_slider'] );
190
-
191
-
192
-
193
- $show_in_slider = sanitize_text_field( $_POST['ex_show_in_homepage'] );
194
-
195
-
196
-
197
- update_post_meta( $post_id, 'show_in_slider', $show_in_slider );
198
-
199
-
200
-
201
- update_post_meta( $post_id, 'ex_show_in_homepage', $show_in_homepage );
202
-
203
-
204
-
205
- $arr = array();
206
-
207
-
208
-
209
- if (isset($_POST['dess_post'])){
210
-
211
-
212
-
213
- $arr = $_POST['dess_post'];
214
-
215
-
216
-
217
- }
218
-
219
-
220
-
221
- foreach ($arr as $key => $value) {
222
-
223
-
224
-
225
- $val = sanitize_text_field($value);
226
-
227
-
228
-
229
- update_post_meta( $post_id, $key, $val );
230
-
231
-
232
-
233
- }
234
-
235
-
236
-
237
- }
238
-
239
- ```
3
+ skdnsndaknsd, sdad