trying to list users & display first – last name

For some reason this is not working for me 🙁

$get_members = array(
    'blog_id' => $GLOBALS['blog_id'],
    'role' => 'sm_flagar',
);

$blogusers = get_users($get_members);
    foreach ($blogusers as $user) {
        echo "<li><a href=\"".$user->user_url."\">". $user->first_name ." ". $user->last_name ."</a></li>";
    }

1 Answer
1

first_name and last_name are stored in the usermeta table. Therefore you have to use get_user_meta() to return these data. Try this code snippet:

$users = get_users(array(
    // blog_id is not required and will be set by WP_User
    'role' => 'sm_flagar'
));

foreach ($users as $user) {
    $firstName = get_user_meta($user->ID, 'first_name', true);
    $lastName = get_user_meta($user->ID, 'last_name', true);

    echo '<li><a href="' . $user->user_url . '">' . $firstName . ' ' . $lastName . '</a></li>' . PHP_EOL;
}

Leave a Comment