通过json_encode获取自定义帖子类型

时间:2017-10-03 10:35:30

标签: php json wordpress

我正在尝试获取所有帖子数据并通过Json(实例过滤)输出但我注意到在Json输出中有缺少的字段,即我的自定义帖子类型:

$args = array( 'post_type' => 'job_feed', 'posts_per_page' => -1 );
$loop = new WP_Query( $args ); 
echo json_encode($loop->get_posts());

我想知道我是如何加入它们的?

以下是数据样本:

{"ID":19,"post_author":"1","post_date":"2017-10-03 09:32:42","post_date_gmt":"2017-10-03 08:32:42","post_content":"","post_title":"Casual Mail Sorter","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"casual-mail-sorter","to_ping":"","pinged":"","post_modified":"2017-10-03 09:32:42","post_modified_gmt":"2017-10-03 08:32:42","post_content_filtered":"","post_parent":0,"guid":"http:\/\/localhost\/Angard\/?post_type=job_feed&p=19","menu_order":0,"post_type":"job_feed","post_mime_type":"","comment_count":"0","filter":"raw"}

我错过了我创建的名为regions

的字段

这是var_dump

{ ["ID"]=> int(19) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2017-10-03 09:32:42" ["post_date_gmt"]=> string(19) "2017-10-03 08:32:42" ["post_content"]=> string(0) "" ["post_title"]=> string(18) "Casual Mail Sorter" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(18) "casual-mail-sorter" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2017-10-03 09:32:42" ["post_modified_gmt"]=> string(19) "2017-10-03 08:32:42" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(53) "http://localhost/Angard/?post_type=job_feed&p=19" ["menu_order"]=> int(0) ["post_type"]=> string(8) "job_feed" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }

0 个答案:

没有答案