This website uses cookies to allow us to see how the site is used. If you continue to use this site, we assume that you are okay with this. If you want to use the sites without cookies, please see our privacy policy.

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:


$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:


A professional WordPress developer for over a decade, Micah has worked on sites for Fortune 100 companies, has released over a dozen WordPress plugins, is a frequent speaker at WordCamps, co-organizes the WordPress Gwinnett meetup, is a co-host on the WP Square One podcast and shares his knowledge by blogging on WordPress development topics. Currently, Micah works at Bluehost as a WordPress contributor.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.