Wordpress 如何通过用户 ID 获取所有用户元数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9411110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wordpress how to get all user meta data by user ID?
提问by Samir Bhattacharjee
how to get all user meta data by user ID in Wordpress?
如何在 Wordpress 中通过用户 ID 获取所有用户元数据?
回答by The Alpha
$user_info = get_userdata($userid);
$username = $user_info->user_login;
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
回答by raison
@Boopathi Rejan nearly had it. Output all of the user meta by using the following code and then look through and find the values you
@Boopathi Rejan 几乎拥有它。使用以下代码输出所有用户元数据,然后查看并找到您的值
$user_info = get_user_meta($current_user->ID);
var_dump($user_info);
You can change the USERID to anything, currently this is setup to display the ID of the logged in user.
您可以将 USERID 更改为任何内容,目前设置为显示登录用户的 ID。
回答by Omprakash Patel
<?php
$current_user = wp_get_current_user();
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
?>
回答by Asadur Zzaman
Use the following code
使用以下代码
$current_user = wp_get_current_user();
$user_info = get_userdata($current_user->ID);
echo $user_info->roles[0];
回答by ecotechie
You can use wpcli for this: In the console type...
wp user meta list user
user = The user login, user email, or user ID of the user to get metadata for.
user = 要为其获取元数据的用户登录名、用户电子邮件或用户 ID。
回答by Boopathi Rajan
simply try this
试试这个
$user_info = get_userdata($userid);
var_dump($user_info);