Update user meta via REST API?

I had to do this yesterday, here’s how I did it. Like you have already done register_meta to appear in the api. register_meta(‘user’, ‘meta_key’, array( “type” => “string”, “show_in_rest” => true, “single” => true, )); Then you will need to make a POST or PUT request to the users endpoint with the meta values in … Read more

Buddypress update user avatar image via REST

I finally found a SOLUTION and i want to post it because can be useful for someone! public function update_user_avatar() { global $json_api; if (!$json_api->query->user_id) { $json_api->error(“Missing ‘user_id’ parameter.”); } if (!$json_api->query->image) { $json_api->error(“Missing ‘image’ parameter.”); } $user_id = $json_api->query->user_id; $base64 = $json_api->query->image; $imgdata = base64_decode($base64); $f = finfo_open(); $mime_type = finfo_buffer($f, $imgdata, FILEINFO_MIME_TYPE); $type_file … Read more

rest api endpoint – accept diacritic characters

Looks to me like WordPress doesn’t enable UTF-8 mode when it runs the regex. https://github.com/WordPress/WordPress/blob/5.2.1/wp-includes/rest-api/class-wp-rest-server.php#L837 In PHP, matching multibyte characters requires the u flag. (The code above just adds the case-insensitive flag). So although some strings will still match (like “Département”), they’re not matching as whole Unicode characters. For example the following pattern matches when … Read more

Create custom post with meta field with AJAX and the WordPress REST API

I haven’t tested your code, but here the $object is an object and not array: // Here, $object is a WP_Post object. function slug_update_post_meta_cb( $value, $object, $field_name ) { return update_post_meta( $object->ID, $field_name, $value ); } And you can actually use register_meta() with a custom post type: register_meta( ‘post’, ‘myfield’, [ ‘object_subtype’ => ‘custom_type’, // … Read more

Get a remote post ID via API given URL

The Posts endpoint accepts a slug parameter when querying for posts, so if you can get the slug from the URL, then you can make request to /wp-json/wp/v2/posts?slug=<slug>. So if the URL is http://example.com/hello-world/ and you know the slug is hello-world, then for example in JavaScript, you can do something like: fetch( ‘http://example.com/wp-json/wp/v2/posts?slug=hello-world’ ) .then( … Read more

How to get all post of custom post type by rest api?

The REST API supports grabbing a maximum of 100 posts at a time, so you’ll have to make an additional call for every 100. Start with wp_remote_get() for 100 posts. While you’re at it, go ahead and retrieve the body of this page and decode it: $transcripts = wp_remote_get(‘http://example.com/wp-json/wp/v2/transcript/?per_page=100’); $transcriptsBody = wp_remote_retrieve_body($transcripts); $transcriptsDecoded = json_decode($transcriptsBody, … Read more