How to get the user description with get_users?

I’m using this piece of code to list users and their information. The problem I’m having is that the description isn’t showing. Obviously it’s because the description lays under “user_meta” and not “users”. But how would I solve that?

<?php
    $blogusers = get_users('include=2,3,4,5,6,7,8');
    foreach ($blogusers as $user) {
        echo '<li>'
        . get_avatar($user->ID, 120) .
        '<br />'
        . $user->display_name .
        '<br />'
        . $user->user_email .
        '<br />'
        . $user->user_description .
        '</li>';
    }
?>

2 Answers
2

The Native get_users() function returns an array of user objects and each on holds

   [ID] => 1
   [user_login] => admin
   [user_pass] => $P$Bxudi6gJMk2GRt2ed3xvZ06c1BPZXi/
   [user_nicename] => admin
   [user_email] => [email protected]
   [user_url] => http://localhost/
   [user_registered] => 2010-06-29 07:08:55
   [user_activation_key] => 
   [user_status] => 0
   [display_name] => Richard Branson

as you can see user_description is not a part of this object since it’s stored in a different table in the database(usermeta as oppose to users).
So Instead of $user->user_description use get_user_meta($user->ID, 'description', true)

<?php
$blogusers = get_users('include=2,3,4,5,6,7,8');
foreach ($blogusers as $user) {
    echo '<li>'
    . get_avatar($user->ID, 120) .
    '<br />'
    . $user->display_name .
    '<br />'
    . $user->user_email .
    '<br />'
    . get_user_meta($user->ID, 'description', true) .
    '</li>';
}

Leave a Comment