WordPress REST API: Modify Response

Modifying response is quite simple, you just have to use filter rest_prepare_{$post_type}. So for modifying response of post type group we have to use filter rest_prepare_group.

add_filter("rest_prepare_group", "group_response", 10, 3);  

Now, let's add a function group_response which will remove the rendered key from the title and content.

function group_response($response, $post, $request) {  
    $response->data['title'] = $response->data['title']['rendered'];
    $response->data['content'] = $response->data['content']['rendered'];
    return $response;

That's it.

comments powered by Disqus