I'm using 'WP REST API Version 2.0-beta12" by http://wp-api.org/ to use REST API, available via HTTP of my site's data in simple JSON format. I have formatted my json output to limit reponse field while list post API - http://example.com/wp-json/wp/v2/posts using rest_prepare_post as follows,
function api_remove_extra_data( $data, $post, $context ) {
// We only want to modify the 'view' context, for reading posts
if ( $context !== 'view' || is_wp_error( $data ) ) {
// Here, we unset any data we don't want to see on the front end:
unset ( $data->data ['link']);
unset ( $data->data ['date_gmt']);
unset ( $data->data ['modified']);
unset ( $data->data ['modified_gmt']);
unset ( $data->data ['type']);
unset ( $data->data ['content']);
unset ( $data->data ['excerpt']);
unset ( $data->data ['author']);
// continue unsetting whatever other fields you want
return $data;
}
}
add_filter( 'rest_prepare_post', 'api_remove_extra_data', 12, 3 );
It works great. But I need full post data in single post API call such as
http://example.com/wp-json/wp/v2/posts/1077
Wordpress version: 4.4.2
Plugin Version : WP REST API 2.0-beta12
By using above filter both posts list API and view single post API return only limited response. How can I get all post data in post single (http://example.com/wp-json/wp/v2/posts/1077) API by keeping limited response in posts list API?