如何让 WordPress 的 REST API 包含用户元数据?

Tom*_*han 2 rest wordpress

我已经建立了一个 WordPress 网站并添加了几个用户。当我直接查看wp_usermeta数据库中的表时,那里有几条记录,因此用户也有一些元数据。

根据文档meta请求用户时应包含,但当我请求时/wp-json/wp/v2/users所有meta字段都是空数组。

我缺少什么?如何通过 REST API 获取有关用户的元数据?

Tom*_*han 6

I managed to find an even easier way to accomplish this, based on this part of the docs.

Not sure where it's best practice to put this code. Since I already have an API-related plugin, I just added the code there.

// legend:    <type>, <meta_key>, <config>
register_meta('user', 'nickname', array(
  "type" => "string",
  "show_in_rest" => true // this is the key part
));
Run Code Online (Sandbox Code Playgroud)

Now I just have to figure out which specific keys I need :)