How to authenticate via API to allow writes/updates

In the documentation I could find, it seems there were four options. OAuth1.0a Server – this appeared to be unsupported and obsolete Application Passwords – This might work, but it seemed a bit awkward to me JSON Web Tokens – this appears to be unsupported and obsolete Basic Authentication – this appears unsuitable as far … Read more

Impossible to create a new WooCommerce customer using Rest API

In the documentation of WP REST User https://wordpress.org/plugins/wp-rest-user/ you have the aswer: To perform further actions after user is registered, write and add_action: add_action(‘wp_rest_user_user_register’, ‘user_registered’); function user_registered($user) { // Do Something } Replace “// Do Something” for the code to change the user role. Something like this (not tested): $u = new WP_User( 3 ); … Read more

WordPress rest API get Posts parent by post ID

As posts can’t have parents, there is no endpoint to get the parent ID of a post. However, pages can have parents, so the page endpoint should return a parent ID, among other things. So, by getting mysite.com/wp-json/wp/v2/pages, you should be able to get the parent attribute, which is “The ID for the parent of … Read more

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