Calling User Nickname

I am currently calling a user's nicename in a function I have:

$users = $user_query-get_results();
foreach( $users as $user ):
echo $user-user_nicename;

I'm trying to call the user's Nickname instead, but nothing I do is working such as:

echo $user-user_nickname;

Is there a special way you have to call a user's nickname?

Thanks

Topic username users Wordpress

Category Web


Try

echo the_author_meta( 'nickname', $current_user->ID );

or you can also use;

$current_user = wp_get_current_user();
echo $current_user->nickname;

This is impossible to answer without seeing your code but there is no user_nickname in the $wpdb->users table and no user_nickname key in the $wpdb->usermeta table by default.

Assuming that $users is a user object then:

$users = $user_query->get_results();  
foreach( $users as $user ) {  
   echo get_user_meta($user->ID,'nickname',true); 
}

Should get you the user nickname.


If you want to query all users, try using the get_users() function. Note that this function returns an array:

<?php
$users = get_users();

foreach( $users as $user ) {
    echo $user['user_nicename'];
}
?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.