How to get the role id from the role name?

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?

Related posts

Leave a Reply

1 comment

  1. 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>';
    }