I am trying to fetch all users with a specific role eg blogger and blogger_pro but my code just returns all users rather than those with that specific role. Hope someone can tell me whats wrong?

The above roles have been added using the plugin User Role Editor


function get_role_specific_users($role){
    $args = array(
        'role'    => $role,
        'orderby' => 'user_nicename',
        'order'   => 'ASC'
    return get_users( $args );

And then calling it like this:

$pro_authors = get_role_specific_users('blogger_pro');
$authors = get_role_specific_users('blogger');

But both arrays just contains all users rather than those with that role :/

  • May be this will help you as this question already answered . ClickHere – Er. Amit Joshi May 31 '18 at 13:50
  • That was the first thing i tried, but the examples there return all users to me, rather than role specific users :/ – Alexander May 31 '18 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.