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 need to retrieve the id of a role by giving it roles name. For example:

if( current_user_can('editor') ) {
 //here I want to retrieve the id of editor.

How can I do that?

share|improve this question
up vote 0 down vote accepted

Try buildin function get_users. The code should be like that:

$args = array(
    'role' => 'editor'
$editors = get_users($args);
foreach ($editors as $user) {
    echo '<li>' . $user->ID . '</li>';
share|improve this answer
It works, thanks for your prompt reply.:) – dev-jim Jun 19 '12 at 17:32

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.