WordPress用のJSON-APIプラグインを使用していますが、ポストタイプから投稿のリストを返すカスタムコントローラを作成しています。ここ WordPress投稿用の出力JSON
[{
"id": 1,
"title": "Sample Post Title"
},
{
"id": 2,
"title": "Sample Post Title"
},
....
]
は私のカスタムコントローラである:私が欲しいの出力は次のようなものである
class JSON_API_Custom_Controller {
public function get_posts_type() {
global $json_api;
$posts_all = array();
$args = array('post_type' => 'shopping', 'posts_per_page' => -1);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()) : $loop->the_post();
$post_id = get_the_ID();
$post_title = get_the_title($post_id);
$posts_all []= array(
'id' => $post_id,
'title' => $post_title
);
endwhile;
}
return $posts_all;
}
}
が、出力は次のとおりです。
{
"status":"ok",
"0":{
"id":1,
"title":"sample title"
},
"1":{
"id":2,
"title":"sample title"
}
}
どのようにオブジェクトのJSON配列することができます私は出力希望の出力が好きですか?
wowのように思えるDown Voteの男が理由なしですべて投票しています! –