WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a site and I need to get the type of user the author is so I can mark it.

The idea is that if an Admin level user post something it has a [ADMIN] tag or something next to their name. I know how to compare things within php but how do I check to see what user type an author is if possible? I can't seem to find any good documentation on the matter.

share|improve this question
up vote 0 down vote accepted

One way would be to use the get_the_author_meta function and pass it user_level

More info on the function: http://codex.wordpress.org/Function_Reference/get_the_author_meta

Then, see this chart to convert user levels to roles (unless you have created custom roles): http://codex.wordpress.org/Roles_and_Capabilities#User_Level_to_Role_Conversion

Example code

$level = get_the_author_meta('user_level');

if($level >= 8) { // Is admin
    // do something
} else if ($level > 2 && $level < 8) { // is editor
    // do something else
share|improve this answer

in the loop:


will get you the capability number of the author. which is close, but not quite what you want.... though you could translate that into the default WP roles.

to get the roles, you could do the following (which will spit out ALL the roles a user has) :

$user = new WP_User( get_the_author_meta('ID'));

if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    foreach ( $user->roles as $role )
        echo $role;


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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