Internal REST API Calls
The WordPress REST API is great, but sometimes we want to load an initial data set to bootstrap a JS application from the API via PHP.
Here is how you can make an API request in PHP without HTTP:
<?php $request = new WP_REST_Request( 'GET', $route ); $request->set_query_params( $params ); $response = rest_do_request( $request ); $data = rest_get_server()->response_to_data( $response, false );
More details: https://wpscholar.com/blog/internal-wp-rest-api-calls/