質問編集履歴

8

変更

2017/04/30 13:39

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -172,6 +172,6 @@
172
172
 
173
173
  ```
174
174
 
175
- single.phpをコピーして新しい優先して読み込まれるはずの、テンプレートsingle-location.php(locationはカスタム投稿タイプ名)としたのですが、
175
+ single.phpをコピーして新しい優先して読み込まれるはずの、テンプレートsingle-location.php(locationはカスタム投稿タイプ名)を作ったのですが、
176
176
 
177
177
  緯度経度がやはり何もページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。コードの書き方が悪いのでしょうか。それともコードをかくファイルがそもそも違うのでしょうか。

7

変更

2017/04/30 13:38

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -94,6 +94,8 @@
94
94
 
95
95
 
96
96
 
97
+ <!--投稿 -->
98
+
97
99
  <?php
98
100
 
99
101
  $args = array(
@@ -120,7 +122,7 @@
120
122
 
121
123
  if( $location->have_posts() ) {
122
124
 
123
- while( $location->have_posts() ) {
125
+ while( $location>have_posts() ) {
124
126
 
125
127
  $location->the_post();
126
128
 
@@ -142,21 +144,29 @@
142
144
 
143
145
  else {
144
146
 
145
- echo 'Oh ohm no products!';
147
+ echo 'Oh ohm no locations!';
146
148
 
147
149
  }
148
150
 
149
- ?>
151
+ ?>
150
152
 
151
-
152
153
 
153
- <?php $lot = get_post_meta( get_the_ID(), 'lot', true );
154
154
 
155
- echo $lot;
155
+ <!--メタデータ取得 -->
156
156
 
157
+ <?php
158
+
159
+ // If we are in a loop we can get the post ID easily
160
+
161
+ $lot = get_post_meta( get_the_ID(), 'lon', true );
162
+
163
+ echo $lot;
164
+
157
- ?>
165
+ ?>
158
166
 
159
167
  <?php get_footer();
168
+
169
+
160
170
 
161
171
 
162
172
 

6

変更

2017/04/30 13:38

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -162,6 +162,6 @@
162
162
 
163
163
  ```
164
164
 
165
- single.phpをコピーしてsingle-location.php(locationはカスタム投稿タイプ名)としたのですが、
165
+ single.phpをコピーして新しい優先して読み込まれるはずの、テンプレートsingle-location.php(locationはカスタム投稿タイプ名)としたのですが、
166
166
 
167
167
  緯度経度がやはり何もページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。コードの書き方が悪いのでしょうか。それともコードをかくファイルがそもそも違うのでしょうか。

5

変更

2017/04/30 13:21

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- wordpressの質問です。カスタム投稿ページの話です。functions.phpにメタボックスを追記し、表示させることまではできました。緯度経度urのデータを投稿ページに持ってくる、表示させるようにすることってできるのでしょうか。それともfunctons.phpのコード弄るだけではできないのでしょうか。
5
+ wordpressの質問です。カスタム投稿ページの話です。functions.phpにメタボックスを追記し、表示させることまではできました。緯度経度urのデータを投稿ページに持ってくる、表示させるようにすることってできるのでしょうか。
6
6
 
7
7
 
8
8
 
@@ -10,371 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- functions.phpに追記した内容
14
13
 
15
- ```php
16
-
17
- //カスタムの追加
18
-
19
- function my_custom_post_location() {
20
-
21
- $labels = array(
22
-
23
- 'name' => _x( 'location', 'post type general name' ),
24
-
25
- 'singular_name' => _x( 'location', 'post type singular name' ),
26
-
27
- 'add_new' => _x( 'Add New', 'book' ),
28
-
29
- 'add_new_item' => __( 'Add New Location' ),
30
-
31
- 'edit_item' => __( 'Edit Location' ),
32
-
33
- 'new_item' => __( 'New Location' ),
34
-
35
- 'all_items' => __( 'All Locations' ),
36
-
37
- 'view_item' => __( 'View Location' ),
38
-
39
- 'search_items' => __( 'Search Locations' ),
40
-
41
- 'not_found' => __( 'No Locations found' ),
42
-
43
- 'not_found_in_trash' => __( 'No Locations found in the Trash' ),
44
-
45
- 'parent_item_colon' => '',
46
-
47
- 'menu_name' => 'Locations'
48
-
49
- );
50
-
51
- $args = array(
52
-
53
- 'labels' => $labels,
54
-
55
- 'description' => 'Holds our locations and location specific data',
56
-
57
- 'public' => true,
58
-
59
- 'menu_position' => 5,
60
-
61
- 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
62
-
63
- 'has_archive' => true,
64
-
65
- );
66
-
67
- register_post_type( 'location', $args );
68
-
69
- }
70
-
71
- add_action( 'init', 'my_custom_post_location' );
72
-
73
-
74
-
75
- //カスタムインタラクションメッセージリンク
76
-
77
- function my_updated_messages( $messages ) {
78
-
79
- global $post, $post_ID;
80
-
81
- $messages['location'] = array(
82
-
83
- 0 => '',
84
-
85
- 1 => sprintf( __('Product updated. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
86
-
87
- 2 => __('Custom field updated.'),
88
-
89
- 3 => __('Custom field deleted.'),
90
-
91
- 4 => __('Location updated.'),
92
-
93
- 5 => isset($_GET['revision']) ? sprintf( __('Location restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
94
-
95
- 6 => sprintf( __('Location published. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
96
-
97
- 7 => __('Location saved.'),
98
-
99
- 8 => sprintf( __('Location submitted. <a target="_blank" href="%s">Preview location</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
100
-
101
- 9 => sprintf( __('Location scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview location</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
102
-
103
- 10 => sprintf( __('Location draft updated. <a target="_blank" href="%s">Preview product</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
104
-
105
- );
106
-
107
- return $messages;
108
-
109
- }
110
-
111
- add_filter( 'post_updated_messages', 'my_updated_messages' );
112
-
113
-
114
-
115
- //文脈ヘルプ
116
-
117
- function my_contextual_help( $contextual_help, $screen_id, $screen ) {
118
-
119
- if ( 'location' == $screen->id ) {
120
-
121
-
122
-
123
- $contextual_help = '<h2>Locations</h2>
124
-
125
- <p>Location show the details of the items that we sell on the website. You can see a list of them on this page in reverse chronological order - the latest one we added is first.</p>
126
-
127
- <p>You can view/edit the details of each Location by clicking on its name, or you can perform bulk actions using the dropdown menu and selecting multiple items.</p>';
128
-
129
-
130
-
131
- } elseif ( 'edit-product' == $screen->id ) {
132
-
133
-
134
-
135
- $contextual_help = '<h2>Editing products</h2>
136
-
137
- <p>This page allows you to view/modify Location details. Please make sure to fill out the available boxes with the appropriate details (product image, price, brand) and <strong>not</strong> add these details to the Location description.</p>';
138
-
139
-
140
-
141
- }
142
-
143
- return $contextual_help;
144
-
145
- }
146
-
147
- add_action( 'contextual_help', 'my_contextual_help', 10, 3 );
148
-
149
-
150
-
151
- //カスタムタクソノミー
152
-
153
- function my_taxonomies_location() {
154
-
155
- $labels = array(
156
-
157
- 'name' => _x( 'Location Categories', 'taxonomy general name' ),
158
-
159
- 'singular_name' => _x( 'Location Category', 'taxonomy singular name' ),
160
-
161
- 'search_items' => __( 'Search Location Categories' ),
162
-
163
- 'all_items' => __( 'All Location Categories' ),
164
-
165
- 'parent_item' => __( 'Parent Location Category' ),
166
-
167
- 'parent_item_colon' => __( 'Parent Location Category:' ),
168
-
169
- 'edit_item' => __( 'Edit Location Category' ),
170
-
171
- 'update_item' => __( 'Update Location Category' ),
172
-
173
- 'add_new_item' => __( 'Add New Location Category' ),
174
-
175
- 'new_item_name' => __( 'New Location Category' ),
176
-
177
- 'menu_name' => __( 'Location Categories' ),
178
-
179
- );
180
-
181
- $args = array(
182
-
183
- 'labels' => $labels,
184
-
185
- 'hierarchical' => true,
186
-
187
- );
188
-
189
- register_taxonomy( 'location_category', 'location', $args );
190
-
191
- }
192
-
193
- add_action( 'init', 'my_taxonomies_location', 0 );
194
-
195
-
196
-
197
- //メタボックス定義
198
-
199
- add_action( 'add_meta_boxes', 'location_box' );
200
-
201
- function location_box() {
202
-
203
- add_meta_box(
204
-
205
- 'location_box',
206
-
207
- __( 'Location', 'myplugin_textdomain' ),
208
-
209
- 'location_box_content',
210
-
211
- 'location',
212
-
213
- 'side',
214
-
215
- 'high'
216
-
217
- );
218
-
219
- }
220
-
221
-
222
-
223
- //メタボックス内容定義
224
-
225
- function location_box_content( $post ) {
226
-
227
- wp_nonce_field( plugin_basename( __FILE__ ), 'location_box_content_nonce' );
228
-
229
- echo '<label for="location"></label>';
230
-
231
- echo '緯度:';
232
-
233
- echo '<input type="text" id="lon_data" name="lon" placeholder="lon" value="'.get_post_meta( $post->ID ,'lon', true ).'"/>';
234
-
235
- echo '<br/>経度:';
236
-
237
- echo '<input type="text" id="lat_data" name="lat" placeholder="lat" value="'.get_post_meta( $post->ID ,'lat', true ).'"/>';
238
-
239
- echo '<br/>link_:';
240
-
241
- echo '<input type="text" id="url" name="url" placeholder="urllink" value="'.get_post_meta( $post->ID ,'url', true ).'"/>';
242
-
243
- }
244
-
245
-
246
-
247
- //送信されたlotデータ処理
248
-
249
- add_action( 'save_post', 'lon_save' );
250
-
251
- function lon_save( $post_id ) {
252
-
253
-
254
-
255
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
256
-
257
- return;
258
-
259
-
260
-
261
- if ( !wp_verify_nonce( $_POST['location_box_content_nonce'], plugin_basename( __FILE__ ) ) )
262
-
263
- return;
264
-
265
-
266
-
267
- if ( 'page' == $_POST['post_type'] ) {
268
-
269
- if ( !current_user_can( 'edit_page', $post_id ) )
270
-
271
- return;
272
-
273
- } else {
274
-
275
- if ( !current_user_can( 'edit_post', $post_id ) )
276
-
277
- return;
278
-
279
- }
280
-
281
- $lon = $_POST['lon'];
282
-
283
- update_post_meta( $post_id, 'lon', $lon );
284
-
285
- }
286
-
287
-
288
-
289
- //送信されたlatデータ処理
290
-
291
- add_action( 'save_post', 'lat_save' );
292
-
293
- function lat_save( $post_id ) {
294
-
295
-
296
-
297
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
298
-
299
- return;
300
-
301
-
302
-
303
- if ( !wp_verify_nonce( $_POST['location_box_content_nonce'], plugin_basename( __FILE__ ) ) )
304
-
305
- return;
306
-
307
-
308
-
309
- if ( 'page' == $_POST['post_type'] ) {
310
-
311
- if ( !current_user_can( 'edit_page', $post_id ) )
312
-
313
- return;
314
-
315
- } else {
316
-
317
- if ( !current_user_can( 'edit_post', $post_id ) )
318
-
319
- return;
320
-
321
- }
322
-
323
- $lat = $_POST['lat'];
324
-
325
- update_post_meta( $post_id, 'lat', $lat );
326
-
327
- }
328
-
329
-
330
-
331
- //送信されたurlデータ処理
332
-
333
- add_action( 'save_post', 'url_save' );
334
-
335
- function url_save( $post_id ) {
336
-
337
-
338
-
339
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
340
-
341
- return;
342
-
343
-
344
-
345
- if ( !wp_verify_nonce( $_POST['location_box_content_nonce'], plugin_basename( __FILE__ ) ) )
346
-
347
- return;
348
-
349
-
350
-
351
- if ( 'page' == $_POST['post_type'] ) {
352
-
353
- if ( !current_user_can( 'edit_page', $post_id ) )
354
-
355
- return;
356
-
357
- } else {
358
-
359
- if ( !current_user_can( 'edit_post', $post_id ) )
360
-
361
- return;
362
-
363
- }
364
-
365
- $url = $_POST['url'];
366
-
367
- update_post_meta( $post_id, 'url', $url );
368
-
369
- }
370
-
371
- ?>
372
-
373
-
374
-
375
-
376
-
377
- ```
378
14
 
379
15
 
380
16
 
@@ -382,7 +18,81 @@
382
18
 
383
19
  ```php
384
20
 
385
- <!--投稿 -->
21
+ <?php
22
+
23
+ /*
24
+
25
+ Template Name Posts: location
26
+
27
+ */
28
+
29
+ ?>
30
+
31
+
32
+
33
+ <?php
34
+
35
+
36
+
37
+ get_header(); ?>
38
+
39
+
40
+
41
+ <div class="wrap">
42
+
43
+ <div id="primary" class="content-area">
44
+
45
+ <main id="main" class="site-main" role="main">
46
+
47
+
48
+
49
+ <?php
50
+
51
+ /* Start the Loop */
52
+
53
+ while ( have_posts() ) : the_post();
54
+
55
+
56
+
57
+ get_template_part( 'template-parts/post/content', get_post_format() );
58
+
59
+
60
+
61
+ // If comments are open or we have at least one comment, load up the comment template.
62
+
63
+ if ( comments_open() || get_comments_number() ) :
64
+
65
+ comments_template();
66
+
67
+ endif;
68
+
69
+
70
+
71
+ the_post_navigation( array(
72
+
73
+ 'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '</span>%title</span>',
74
+
75
+ 'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '</span></span>',
76
+
77
+ ) );
78
+
79
+
80
+
81
+ endwhile; // End of the loop.
82
+
83
+ ?>
84
+
85
+
86
+
87
+ </main><!-- #main -->
88
+
89
+ </div><!-- #primary -->
90
+
91
+ <?php get_sidebar(); ?>
92
+
93
+ </div><!-- .wrap -->
94
+
95
+
386
96
 
387
97
  <?php
388
98
 
@@ -410,7 +120,7 @@
410
120
 
411
121
  if( $location->have_posts() ) {
412
122
 
413
- while( $location>have_posts() ) {
123
+ while( $location->have_posts() ) {
414
124
 
415
125
  $location->the_post();
416
126
 
@@ -432,25 +142,23 @@
432
142
 
433
143
  else {
434
144
 
435
- echo 'Oh ohm no locations!';
145
+ echo 'Oh ohm no products!';
436
146
 
437
147
  }
438
148
 
439
- ?>
149
+ ?>
150
+
151
+
152
+
153
+ <?php $lot = get_post_meta( get_the_ID(), 'lot', true );
154
+
155
+ echo $lot;
156
+
157
+ ?>
158
+
159
+ <?php get_footer();
440
160
 
441
161
 
442
-
443
- <!--メタデータ取得 -->
444
-
445
- <?php
446
-
447
- // If we are in a loop we can get the post ID easily
448
-
449
- $lot = get_post_meta( get_the_ID(), 'lon', true );
450
-
451
- echo $lot;
452
-
453
- ?>
454
162
 
455
163
  ```
456
164
 

4

訂正

2017/04/30 13:20

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -456,4 +456,4 @@
456
456
 
457
457
  single.phpをコピーしてsingle-location.php(locationはカスタム投稿タイプ名)としたのですが、
458
458
 
459
- 緯度経度がやはり何もページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。
459
+ 緯度経度がやはり何もページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。コードの書き方が悪いのでしょうか。それともコードをかくファイルがそもそも違うのでしょうか。

3

訂正

2017/04/30 13:04

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -456,4 +456,4 @@
456
456
 
457
457
  single.phpをコピーしてsingle-location.php(locationはカスタム投稿タイプ名)としたのですが、
458
458
 
459
- 緯度経度がやはりページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。
459
+ 緯度経度がやはり何もページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。

2

追加

2017/04/30 13:02

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -372,6 +372,16 @@
372
372
 
373
373
 
374
374
 
375
+
376
+
377
+ ```
378
+
379
+
380
+
381
+ [single-location.php]
382
+
383
+ ```php
384
+
375
385
  <!--投稿 -->
376
386
 
377
387
  <?php
@@ -442,6 +452,8 @@
442
452
 
443
453
  ?>
444
454
 
445
-
446
-
447
455
  ```
456
+
457
+ single.phpをコピーしてsingle-location.php(locationはカスタム投稿タイプ名)としたのですが、
458
+
459
+ 緯度経度がやはりページに表示されないです。single-location.phpが読み込まれて表示されるにはどうすればいいのでしょうか。

1

追記

2017/04/30 13:02

投稿

destrudo
destrudo

スコア143

test CHANGED
File without changes
test CHANGED
@@ -2,8 +2,446 @@
2
2
 
3
3
 
4
4
 
5
- wordpressの質問です。カスタム投稿ページの話です。functions.phpにメタボックスを追記し、表示させることまではできました。緯度経度urのデータを投稿ページに持ってくる、表示させるようにすることってできるのでしょうか。
5
+ wordpressの質問です。カスタム投稿ページの話です。functions.phpにメタボックスを追記し、表示させることまではできました。緯度経度urのデータを投稿ページに持ってくる、表示させるようにすることってできるのでしょうか。それともfunctons.phpのコード弄るだけではできないのでしょうか。
6
6
 
7
7
 
8
8
 
9
9
  [参考にしたサイト](https://www.smashingmagazine.com/2012/11/complete-guide-custom-post-types/)
10
+
11
+
12
+
13
+ functions.phpに追記した内容
14
+
15
+ ```php
16
+
17
+ //カスタムの追加
18
+
19
+ function my_custom_post_location() {
20
+
21
+ $labels = array(
22
+
23
+ 'name' => _x( 'location', 'post type general name' ),
24
+
25
+ 'singular_name' => _x( 'location', 'post type singular name' ),
26
+
27
+ 'add_new' => _x( 'Add New', 'book' ),
28
+
29
+ 'add_new_item' => __( 'Add New Location' ),
30
+
31
+ 'edit_item' => __( 'Edit Location' ),
32
+
33
+ 'new_item' => __( 'New Location' ),
34
+
35
+ 'all_items' => __( 'All Locations' ),
36
+
37
+ 'view_item' => __( 'View Location' ),
38
+
39
+ 'search_items' => __( 'Search Locations' ),
40
+
41
+ 'not_found' => __( 'No Locations found' ),
42
+
43
+ 'not_found_in_trash' => __( 'No Locations found in the Trash' ),
44
+
45
+ 'parent_item_colon' => '',
46
+
47
+ 'menu_name' => 'Locations'
48
+
49
+ );
50
+
51
+ $args = array(
52
+
53
+ 'labels' => $labels,
54
+
55
+ 'description' => 'Holds our locations and location specific data',
56
+
57
+ 'public' => true,
58
+
59
+ 'menu_position' => 5,
60
+
61
+ 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
62
+
63
+ 'has_archive' => true,
64
+
65
+ );
66
+
67
+ register_post_type( 'location', $args );
68
+
69
+ }
70
+
71
+ add_action( 'init', 'my_custom_post_location' );
72
+
73
+
74
+
75
+ //カスタムインタラクションメッセージリンク
76
+
77
+ function my_updated_messages( $messages ) {
78
+
79
+ global $post, $post_ID;
80
+
81
+ $messages['location'] = array(
82
+
83
+ 0 => '',
84
+
85
+ 1 => sprintf( __('Product updated. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
86
+
87
+ 2 => __('Custom field updated.'),
88
+
89
+ 3 => __('Custom field deleted.'),
90
+
91
+ 4 => __('Location updated.'),
92
+
93
+ 5 => isset($_GET['revision']) ? sprintf( __('Location restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
94
+
95
+ 6 => sprintf( __('Location published. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
96
+
97
+ 7 => __('Location saved.'),
98
+
99
+ 8 => sprintf( __('Location submitted. <a target="_blank" href="%s">Preview location</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
100
+
101
+ 9 => sprintf( __('Location scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview location</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
102
+
103
+ 10 => sprintf( __('Location draft updated. <a target="_blank" href="%s">Preview product</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
104
+
105
+ );
106
+
107
+ return $messages;
108
+
109
+ }
110
+
111
+ add_filter( 'post_updated_messages', 'my_updated_messages' );
112
+
113
+
114
+
115
+ //文脈ヘルプ
116
+
117
+ function my_contextual_help( $contextual_help, $screen_id, $screen ) {
118
+
119
+ if ( 'location' == $screen->id ) {
120
+
121
+
122
+
123
+ $contextual_help = '<h2>Locations</h2>
124
+
125
+ <p>Location show the details of the items that we sell on the website. You can see a list of them on this page in reverse chronological order - the latest one we added is first.</p>
126
+
127
+ <p>You can view/edit the details of each Location by clicking on its name, or you can perform bulk actions using the dropdown menu and selecting multiple items.</p>';
128
+
129
+
130
+
131
+ } elseif ( 'edit-product' == $screen->id ) {
132
+
133
+
134
+
135
+ $contextual_help = '<h2>Editing products</h2>
136
+
137
+ <p>This page allows you to view/modify Location details. Please make sure to fill out the available boxes with the appropriate details (product image, price, brand) and <strong>not</strong> add these details to the Location description.</p>';
138
+
139
+
140
+
141
+ }
142
+
143
+ return $contextual_help;
144
+
145
+ }
146
+
147
+ add_action( 'contextual_help', 'my_contextual_help', 10, 3 );
148
+
149
+
150
+
151
+ //カスタムタクソノミー
152
+
153
+ function my_taxonomies_location() {
154
+
155
+ $labels = array(
156
+
157
+ 'name' => _x( 'Location Categories', 'taxonomy general name' ),
158
+
159
+ 'singular_name' => _x( 'Location Category', 'taxonomy singular name' ),
160
+
161
+ 'search_items' => __( 'Search Location Categories' ),
162
+
163
+ 'all_items' => __( 'All Location Categories' ),
164
+
165
+ 'parent_item' => __( 'Parent Location Category' ),
166
+
167
+ 'parent_item_colon' => __( 'Parent Location Category:' ),
168
+
169
+ 'edit_item' => __( 'Edit Location Category' ),
170
+
171
+ 'update_item' => __( 'Update Location Category' ),
172
+
173
+ 'add_new_item' => __( 'Add New Location Category' ),
174
+
175
+ 'new_item_name' => __( 'New Location Category' ),
176
+
177
+ 'menu_name' => __( 'Location Categories' ),
178
+
179
+ );
180
+
181
+ $args = array(
182
+
183
+ 'labels' => $labels,
184
+
185
+ 'hierarchical' => true,
186
+
187
+ );
188
+
189
+ register_taxonomy( 'location_category', 'location', $args );
190
+
191
+ }
192
+
193
+ add_action( 'init', 'my_taxonomies_location', 0 );
194
+
195
+
196
+
197
+ //メタボックス定義
198
+
199
+ add_action( 'add_meta_boxes', 'location_box' );
200
+
201
+ function location_box() {
202
+
203
+ add_meta_box(
204
+
205
+ 'location_box',
206
+
207
+ __( 'Location', 'myplugin_textdomain' ),
208
+
209
+ 'location_box_content',
210
+
211
+ 'location',
212
+
213
+ 'side',
214
+
215
+ 'high'
216
+
217
+ );
218
+
219
+ }
220
+
221
+
222
+
223
+ //メタボックス内容定義
224
+
225
+ function location_box_content( $post ) {
226
+
227
+ wp_nonce_field( plugin_basename( __FILE__ ), 'location_box_content_nonce' );
228
+
229
+ echo '<label for="location"></label>';
230
+
231
+ echo '緯度:';
232
+
233
+ echo '<input type="text" id="lon_data" name="lon" placeholder="lon" value="'.get_post_meta( $post->ID ,'lon', true ).'"/>';
234
+
235
+ echo '<br/>経度:';
236
+
237
+ echo '<input type="text" id="lat_data" name="lat" placeholder="lat" value="'.get_post_meta( $post->ID ,'lat', true ).'"/>';
238
+
239
+ echo '<br/>link_:';
240
+
241
+ echo '<input type="text" id="url" name="url" placeholder="urllink" value="'.get_post_meta( $post->ID ,'url', true ).'"/>';
242
+
243
+ }
244
+
245
+
246
+
247
+ //送信されたlotデータ処理
248
+
249
+ add_action( 'save_post', 'lon_save' );
250
+
251
+ function lon_save( $post_id ) {
252
+
253
+
254
+
255
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
256
+
257
+ return;
258
+
259
+
260
+
261
+ if ( !wp_verify_nonce( $_POST['location_box_content_nonce'], plugin_basename( __FILE__ ) ) )
262
+
263
+ return;
264
+
265
+
266
+
267
+ if ( 'page' == $_POST['post_type'] ) {
268
+
269
+ if ( !current_user_can( 'edit_page', $post_id ) )
270
+
271
+ return;
272
+
273
+ } else {
274
+
275
+ if ( !current_user_can( 'edit_post', $post_id ) )
276
+
277
+ return;
278
+
279
+ }
280
+
281
+ $lon = $_POST['lon'];
282
+
283
+ update_post_meta( $post_id, 'lon', $lon );
284
+
285
+ }
286
+
287
+
288
+
289
+ //送信されたlatデータ処理
290
+
291
+ add_action( 'save_post', 'lat_save' );
292
+
293
+ function lat_save( $post_id ) {
294
+
295
+
296
+
297
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
298
+
299
+ return;
300
+
301
+
302
+
303
+ if ( !wp_verify_nonce( $_POST['location_box_content_nonce'], plugin_basename( __FILE__ ) ) )
304
+
305
+ return;
306
+
307
+
308
+
309
+ if ( 'page' == $_POST['post_type'] ) {
310
+
311
+ if ( !current_user_can( 'edit_page', $post_id ) )
312
+
313
+ return;
314
+
315
+ } else {
316
+
317
+ if ( !current_user_can( 'edit_post', $post_id ) )
318
+
319
+ return;
320
+
321
+ }
322
+
323
+ $lat = $_POST['lat'];
324
+
325
+ update_post_meta( $post_id, 'lat', $lat );
326
+
327
+ }
328
+
329
+
330
+
331
+ //送信されたurlデータ処理
332
+
333
+ add_action( 'save_post', 'url_save' );
334
+
335
+ function url_save( $post_id ) {
336
+
337
+
338
+
339
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
340
+
341
+ return;
342
+
343
+
344
+
345
+ if ( !wp_verify_nonce( $_POST['location_box_content_nonce'], plugin_basename( __FILE__ ) ) )
346
+
347
+ return;
348
+
349
+
350
+
351
+ if ( 'page' == $_POST['post_type'] ) {
352
+
353
+ if ( !current_user_can( 'edit_page', $post_id ) )
354
+
355
+ return;
356
+
357
+ } else {
358
+
359
+ if ( !current_user_can( 'edit_post', $post_id ) )
360
+
361
+ return;
362
+
363
+ }
364
+
365
+ $url = $_POST['url'];
366
+
367
+ update_post_meta( $post_id, 'url', $url );
368
+
369
+ }
370
+
371
+ ?>
372
+
373
+
374
+
375
+ <!--投稿 -->
376
+
377
+ <?php
378
+
379
+ $args = array(
380
+
381
+ 'post_type' => 'location',
382
+
383
+ 'tax_query' => array(
384
+
385
+ array(
386
+
387
+ 'taxonomy' => 'location_category',
388
+
389
+ 'field' => 'slug',
390
+
391
+ 'terms' => 'boardgames'
392
+
393
+ )
394
+
395
+ )
396
+
397
+ );
398
+
399
+ $location = new WP_Query( $args );
400
+
401
+ if( $location->have_posts() ) {
402
+
403
+ while( $location>have_posts() ) {
404
+
405
+ $location->the_post();
406
+
407
+ ?>
408
+
409
+ <h1><?php the_title() ?></h1>
410
+
411
+ <div class='content'>
412
+
413
+ <?php the_content() ?>
414
+
415
+ </div>
416
+
417
+ <?php
418
+
419
+ }
420
+
421
+ }
422
+
423
+ else {
424
+
425
+ echo 'Oh ohm no locations!';
426
+
427
+ }
428
+
429
+ ?>
430
+
431
+
432
+
433
+ <!--メタデータ取得 -->
434
+
435
+ <?php
436
+
437
+ // If we are in a loop we can get the post ID easily
438
+
439
+ $lot = get_post_meta( get_the_ID(), 'lon', true );
440
+
441
+ echo $lot;
442
+
443
+ ?>
444
+
445
+
446
+
447
+ ```