我是 PHP 新手,我正在研究 wordpress JSON api。我想删除 JSON 数组中的键:值对。请帮忙
{
"status":"ok",
"post":{
"id":23,
"type":"post",
"slug":"head-ache",
"url":"http:\/\/xyz.com\/maruthuvam\/2015\/06\/17\/head-ache\/",
"status":"publish",
"title":"Head Ache",
"title_plain":"Head Ache",
"content":"<p>content<\/p>\n<p> <\/p>\n",
"excerpt":"<p>content <\/p>\n",
"date":"2015-06-17 19:35:47",
"modified":"2015-06-18 07:35:39",
"categories":[
{
"id":1,
"slug":"head",
"title":"Head",
"description":"http:\/\/xyz.com\/maruthuvam\/wp-content\/uploads\/2015\/06\/universa_-male_head_3d_model_01.jpg",
"parent":0,
"post_count":3
}
],
"tags":[
],
"author":{
"id":1,
"slug":"admin",
"name":"admin",
"first_name":"",
"last_name":"",
"nickname":"admin",
"url":"",
"description":""
},
"comments":[
],
"attachments":[
],
"comment_count":0,
"comment_status":"closed",
"custom_fields":{
}
},
"next_url":"http:\/\/xyz.com\/maruthuvam\/2015\/06\/17\/head- lice\/"
}
例如,我想从 "post" 和 "post_count":0 中删除 "slug":"head-ache",从 "categories" 和 "next-url" 中删除。请帮忙。
更新::
我已经在 core.php 中添加了代码,但它不起作用。你能帮帮我吗?
public function get_post() {
global $json_api, $post;
$post = $json_api->introspector->get_current_post();
if ($post) {
$previous = get_adjacent_post(false, '', true);
$next = get_adjacent_post(false, '', false);
$response = array(
'post' => new JSON_API_Post($post)
);
if ($previous) {
$response['previous_url'] = get_permalink($previous->ID);
}
if ($next) {
$response['next_url'] = get_permalink($next->ID);
}
// parsing json
$arr = decode_json($response);
// removing the value
unset($arr['post']['slug']);
// and back to json
$response = json_encode($arr);
return $response;
} else {
$json_api->error("Not found.");
}
}