Search code examples
wordpresswordpress-rest-api

WP_REST_REQUEST: how to add "_embed" to request parameters


I added this function to my wordpress REST API to have a custom endpoint

function getSettimanaEventi(){
$request = new WP_REST_Request( 'GET', '/wp/v2/tribe_events' );
$request['_embed'] = '1';
$request['filter[meta_query][0][key]'] = '_EventStartDate';
$request['filter[meta_query][0][value][0]'] = '2017-07-03 00:00:00';
$request['filter[meta_query][0][value][1]'] = '2017-07-09 00:00:00';
$request['filter[meta_query][0][compare]'] = 'BETWEEN';
$request['filter[meta_query][0][type]'] = 'DATE';


$response = rest_do_request( $request );
return $response;

i got a response but there isn't the embedded content.

I know the parameters with a leading '_' are private but i need embedded content. How can i do?


Solution

  • The only way i found is to add the "_embed" parameter to the url (when you call it from Postman for example) and delete it from the request parameters