Wordpress REST API and User meta data

I created two custom REST API endpoint to createupdate a user metadata a get its value.I use update_user_meta() and ge

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.

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.

Share Improve this question asked Jun 15, 2019 at 11:36 enfixenfix 1131 silver badge5 bronze badges 2
  • 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 Commented Jun 15, 2019 at 14:04
  • I don't know where is in WP source code – enfix Commented Jun 15, 2019 at 16:30
Add a comment  | 

1 Answer 1

Reset to default 8

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 ] );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745398097a4625973.html

相关推荐

  • Wordpress REST API and User meta data

    I created two custom REST API endpoint to createupdate a user metadata a get its value.I use update_user_meta() and ge

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信