WP REST API format response
Since you’re filtering with the rest_prepare_{post_type} filter, you could restrict it to the WP_REST_Posts_Controller::get_items() callback, with the rest_{post_type}_query filter: add_filter( ‘rest_post_query’, function( $args ) { add_filter( ‘rest_prepare_post’, ‘api_remove_extra_data’, 12, 3 ); return $args; } ); where the post type is post. Note that in general we always want to return the filter value and I … Read more