Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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:

the_author_meta('user_level'); 

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;
};

http://wordpress.org/support/topic/get-a-users-role-by-user-id?replies=20#post-1363118

share|improve this answer

Your Answer

 
discard

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.