うさぎのイラスト

ネットアンサー55備忘録

web技術を書いていきます

$postで情報を確認しよう

-2016年01月08日-
1<?php
2if(have_posts()): while(have_posts()): the_post();
3var_dump($post);
4?>
5~~
6<?php endwhile; endif;
7wp_reset_query();
8?>
で個別ページの持っている情報を見ることができる。
1object(WP_Post)#3650 (24) {
2  ["ID"]=>
3  int(1362)
4  ["post_author"]=>
5  string(1) "5"
6  ["post_date"]=>
7  string(19) "2016-01-07 13:33:25"
8  ["post_date_gmt"]=>
9  string(19) "2016-01-07 04:33:25"
10  ["post_content"]=>
11  string(0) ""
12  ["post_title"]=>
13  string(9) "食の旅"
14  ["post_excerpt"]=>
15  string(0) ""
16  ["post_status"]=>
17  string(7) "publish"
18  ["comment_status"]=>
19  string(6) "closed"
20  ["ping_status"]=>
21  string(6) "closed"
22  ["post_password"]=>
23  string(0) ""
24  ["post_name"]=>
25  string(27) "%e9%a3"
26  ["to_ping"]=>
27  string(0) ""
28  ["pinged"]=>
29  string(0) ""
30  ["post_modified"]=>
31  string(19) "2016-01-07 16:48:45"
32  ["post_modified_gmt"]=>
33  string(19) "2016-01-07 07:48:45"
34  ["post_content_filtered"]=>
35  string(0) ""
36  ["post_parent"]=>
37  int(0)
38  ["guid"]=>
39  string(50) "http://test△△△△/?post_type=sele△△&#038;p=1362"
40  ["menu_order"]=>
41  int(0)
42  ["post_type"]=>
43  string(10) "sele△△"
44  ["post_mime_type"]=>
45  string(0) ""
46  ["comment_count"]=>
47  string(1) "0"
48  ["filter"]=>
49  string(3) "raw"
50}
上の中なら例えば ["post_title"]=>string(9) "食の旅"の情報を出力したい場合は下記のように書き込む。