We are using this code to get a list of all contributors but we would like to exclude the admin from this list. Currently the admin and any role above the contributor role is being shown with this code.

$args  = array('exclude' => array( 10, 18, 4, 15, 9 ), 'who' => 'contributors' );$wp_user_query = new WP_User_Query($args);
  • We are just looking to get all contributors ONLY and exclude certain contributors from this list. I have tried to follow the documentation but couldn't figure this out. Also there doesn't seem to be a specific answer anywhere for this type of example. – Joanna Mikalai Jul 29 at 14:29

I realize now that you're not talking about WP_Query but WP_User_Query. Looking at the documentation for WP_User_Query it says this about the who parameter:

  • who (string) - Which users to query. Currently only 'authors' is supported. Default is all users.

Instead you can use the role parameter and exclude certain users by ID like so:

// Grab all contributors
$contributor_ids = new WP_User_Query( array(
    'role'      => 'contributor',
    'exclude'   => array( 10, 18, 4, 15, 9 )
) );

You can also pass multiple roles to the above. For more info check out the section on roles.

Your Answer

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

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