get_user_meta()
get_user_meta( int $user_id, string $key = ”, bool $single = false )
检索用户的用户元字段。
Retrieve user meta field for a user.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$user_id | (int) | 必需 | 用户ID。 |
$key | (string) | 可选 | 要检索的元密钥。默认情况下,返回所有键的数据。 |
$single | (bool) | 可选 | 是否返回单个值。 |
返回(Return)
(mixed)将是一个数组,如果$single为false。如果$single为true,则为元数据字段的值。
源码(Source)
/** * Retrieve user meta field for a user. * * @since 3.0.0 * @link https://codex.wordpress.org/Function_Reference/get_user_meta * * @param int $user_id User ID. * @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. * @param bool $single Whether to return a single value. * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. */ function get_user_meta($user_id, $key = '', $single = false) { return get_metadata('user', $user_id, $key, $single); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
3.0.0 | wp-includes/user.php:827 | 20 | 1 function |
笔记(Notes)
如果键不存在,函数将根据$single参数的值返回空字符串或空数组
获取所有元数据
若要检查返回值是否为空(即不存在),可以使用以下内容:
get_user_meta() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_user_meta/