0

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

1
  • 1
    What does $user_query->get_results() return? Commented May 21, 2012 at 14:50

3 Answers 3

5

Try

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

or you can also use;

$current_user = wp_get_current_user();
echo $current_user->nickname;
1
  • 2
    Please explain how to use this with the OP's code.
    – s_ha_dum
    Commented Sep 5, 2013 at 13:08
2

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'];
}
?>
6
  • I have a custom code that provides a list of users based on certain criteria, but I am just not able to successfully call (and display) the user's nickname instead of their nicename.
    – Teddy
    Commented May 21, 2012 at 14:26
  • 1
    How are we supposed to answer/help, without seeing this "custom code"? Commented May 21, 2012 at 14:37
  • I didn't think the code itself was really relevant, I was just asking in general for how to call a user's nickname.
    – Teddy
    Commented May 21, 2012 at 14:55
  • Okay, now I'm confused. :) If the code itself isn't really relevant, why did you bring it up? Commented May 21, 2012 at 15:41
  • I think I'm confused too... ;) Your original reply mentioned querying all users, which I am not doing. I am just trying to change the way my query displays on my page (using nickname instead of nicename) so that a user's first and last name will appear.
    – Teddy
    Commented May 21, 2012 at 16:22
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.