Remove unnecessary fields from json response
-
I want retrieve the last posts using, get_recent_post
https://mydomain.com/api/get_recent_posts/
Everything works fine, but i want call this api from my Android application and i want minimize the data sent by the server.
the response format is the following:
"status":"ok", "count":5, "count_total":5, "pages":1, "posts":[]
and each post has the following fields :
"id":21, "type":"post", "slug":"articolo-prova-3", "url":"https://mydomain.com/index.php/2014/02/17/articolo-prova-3/", "status":"publish", "title":"Articolo prova 3", "title_plain":"Articolo prova 3", "content":"", "excerpt":"", "date":"2014-02-17 16:00:12", "modified":"2014-02-17 16:12:04", "categories":[], "tags":{}, "author":{}, "comments":{}, "attachments":[], "comment_count":0, "comment_status":"open", "thumbnail":"https://mydomain.com/wp-content/uploads/2014/02/20100204104618Terminator-150x150.jpg", "custom_fields":{}, "thumbnail_size":"thumbnail", "thumbnail_images":{}
now i want lightweight the response removing some of this field/arrays
i’m trying to modify the core api without success, i think it’s easy but not enough for a PHP noob like me ??
public function get_posts() { global $json_api; $url = parse_url($_SERVER['REQUEST_URI']); $defaults = array( 'ignore_sticky_posts' => true ); $query = wp_parse_args($url['query']); unset($query['json']); unset($query['post_status']); $query = array_merge($defaults, $query); $posts = $json_api->introspector->get_posts($query); foreach ($posts as $post) { foreach ($post as $field) { unset($field['categories']); //i want remove this unset($field['author']); //i want remove this unset($field['type']); //i want remove this } } $result = $this->posts_result($posts); $result['query'] = $query; return $result; }
What i’m doing wrong?
Thank you ??
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Remove unnecessary fields from json response’ is closed to new replies.