Get all Users except Subscribers in WordPress
This, small and short as usual, tutorial will show you how to put WordPress User objects into array. For my needs, it wasn’t necessary to put Subscribers, but Administrators, Editors and Authors. You can easily exclude any, like Contributors too.
Just put this snippet into your code and you will have users as WP objects inside allowed_users array:
$all_users = get_users(); $allowed_users = array(); foreach ( $all_users as $user ): $wp_user = new WP_User($user->ID); if ( !in_array( 'subscriber', $wp_user->roles ) ): array_push($allowed_users, $user); endif; endforeach;
Share this story:
One response to “Get all Users except Subscribers in WordPress”
Leave a Reply