Wordpress, how to get all user metadata by user ID?

How to get all user metadata by user ID in Wordpress?

+4
source share
6 answers
$user_info = get_userdata($userid); $username = $user_info->user_login; $first_name = $user_info->first_name; $last_name = $user_info->last_name; 
+8
source

@ Boopathy Reyan almost had it. Display all user meta data using the following code, and then browse and find the values ​​you

  $user_info = get_user_meta($current_user->ID); var_dump($user_info); 

You can change the USERID to anything, this is currently a setting to display the registered user ID.

+6
source
 <?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 />'; ?> 
+2
source

Use the following code

 $current_user = wp_get_current_user(); $user_info = get_userdata($current_user->ID); echo $user_info->roles[0]; 
+1
source

try it

 $user_info = get_userdata($userid); var_dump($user_info); 
0
source

You can use wpcli for this : In a console like ...

 wp user meta list user 

user = User login, user email, or user ID for metadata.

0
source

Source: https://habr.com/ru/post/1397999/


All Articles