Wordpress how to get all user meta data by user ID?

后端 未结 6 1409
独厮守ぢ
独厮守ぢ 2020-12-18 08:43

how to get all user meta data by user ID in Wordpress?

相关标签:
6条回答
  • 2020-12-18 09:00

    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.

    0 讨论(0)
  • 2020-12-18 09:02
      $user_info = get_userdata($userid);
      $username = $user_info->user_login;
      $first_name = $user_info->first_name;
      $last_name = $user_info->last_name;
    
    0 讨论(0)
  • 2020-12-18 09:09
    <?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 />';
    ?> 
    
    0 讨论(0)
  • 2020-12-18 09:10

    simply try this

    $user_info = get_userdata($userid);
    var_dump($user_info);
    
    0 讨论(0)
  • 2020-12-18 09:12

    @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

     $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.

    0 讨论(0)
  • 2020-12-18 09:18

    Use the following code

    $current_user = wp_get_current_user();
    
    $user_info = get_userdata($current_user->ID);
    
    echo $user_info->roles[0];
    
    0 讨论(0)
提交回复
热议问题