Accessing Custom REST endpoint with rest_do_request()

I done a bit of experimenting and in my custom endpoint i replaced : wp_send_json($items); with : return new \WP_REST_Response ($items); However I do not see how to extract my data from the WP_REST_Request object. I can see it is there with var_dump. But I can find no documentation as to how to access the … Read more

Media gallery images url instead of ID on WP API

Have a look at wp_get_attachment_image_url for getting the URL of images: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_url/ or wp_get_attachment_url for getting the URL for attachments other than images: https://developer.wordpress.org/reference/functions/wp_get_attachment_url/. These functions return the URLs only and you could use them like so: // your JSON $json = ‘ { “Gallery Images”: [ “1833”, “1834”, “1835” ] } ‘; // convert … Read more

how to create JSON array [] for REST response?

Just use another array() inside user array() $response = array(); $response[] = array( ‘version’ => ‘1.0’, ‘user’ => array( array( ‘first_name’ => ‘Razon’, ‘last_name’ => ‘komar pal’, ’email’ => ‘[email protected]’, ‘id’ => 10, ) ), ); return rest_ensure_response($response); It will output like: [ { “version”: “1.0”, “user”: [ { “first_name”: “Razon”, “last_name”: “komar pal”, “email”: … Read more