0

I created two custom REST API endpoint to create/update a user metadata a get its value.
I use update_user_meta() and get_user_meta().
Both work properly, in the API where I use get_user_meta() I have the value, but when I use the native REST API of Wordpress

 /users/me?context=edit

In meta object I have an empty array.

enter image description here

  • I don’t have the source to hand to check but I’d guess it only includes a whitelisted set of properties in that list. Can you find the REST controller that serves that endpoint? – Rup Jun 15 at 14:04
  • I don't know where is in WP source code – enfix Jun 15 at 16:30
2

There's a lot of stuff saved as user meta that has no business being sent over the REST API, therefore the default endpoints do not include every piece of arbitrary meta automatically. If you want a piece of meta to appear in the REST API responses you need to register it with register_meta(), with show_in_rest set to true:

register_meta( 'user', 'your_meta_key_here', [ 'show_in_rest' => true ] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.