Get WordPress User data By Username Or Login

In your theme code or plugin code, if you know the user name or user login of the WordPress user, you can easily obtain all the user information stored in WordPress database using the below function.


get_userdatabylogin(‘username/login name’)

How to use this function

$username is the variable in which you have the username or login name of the user.

$userinfo = get_userdatabylogin($username);

How to access various user information fields

Remember that the output $userinfo is a ‘Object’ and not an array. I have put all the user fields you get by the execution of this function in the $userinfo object.

Field Description


User ID, this is a numeric unique user id of the user e.g. 4


The login name or user name of the user which he/she uses to log in to WordPress


The WordPress Hash generated password. Remember that it is not the actual password that user uses to login. It is the hash generated password using the function wp_hash_password()


This is the sanitized version of the username, for example the user name is ‘Sanjeev Mishra’, then WordPress creates a username slug as ‘sanjeev-mishra’ which is used in the author page links and so on. This slug or sanitized username is called user_nicename


Email of the user


The Website of the user entered in the ‘Profile’ section of the WP-admin


The Timestamp when user has registered


This is the user activation key, mostly useful before the user registration is activated


User Status, it does not seem to have any significance in the recent WordPress versions


This is the ‘Display Name’ user has selected in the Profile section on admin panel.


This is the First Name of the user inputted thru the Profile section on admin panel.


This is the Last Name of the user inputted thru the Profile section on admin panel.


This is the Nick Name of the user inputted thru the Profile section on admin panel.


Description of the user inputted thru the Profile section on admin panel.


The user_level which indicates the authority of the user on the blog. You can refer WordPress User Level Guide for more details


The admin color scheme the user has selected ‘fresh’ or ‘classic’


The primary blog of user, mostly useful on WPMU. Usually not populated for normal WordPress installation


‘true’ or ‘false’ -> Denotes that whether the Visual Editor is enabled or disabled for the user. Value equal to ‘true’ indicates that visual editor is enabled



  1. Vijendra Mishra

    February 26, 2010 at 2:30 pm

    Nice Article Tejaswini… can we export this user data in to excel format??

  2. Ethan

    February 27, 2010 at 1:11 am

    This is going to be really useful when I go to design a “about logged in user” page next week. Thanks!

  3. NavaPavan

    March 3, 2010 at 1:47 pm

    Is it flaw of wordpress? Then hat about the security

  4. Martine

    March 23, 2010 at 11:55 pm


    Hoe kan ik de toepassing van deze code en maken het werken in WordPress? Weet iemand een WordPress plugin die extra vraag velden voor de registratie van commenters voegt daaraan toe? Is er een WordPress-plugin om een uitgebreid profiel door zelfgemaakte vragen voor commenters? Bedankt!

  5. niraj

    April 16, 2010 at 8:46 pm

    where to use these commands?

  6. Thank you very much Great post…thanks for share this. ………

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>