[wp-hackers] Get All Users with Specific capability

Ryan Bilesky rbilesky at gmail.com
Tue Feb 15 01:10:25 UTC 2011


I need to get all users who have a specific capability, I have a function
with this code:

global $wpdb;
$members = array();

// Get all user ID's
$members_search = $wpdb->get_results("SELECT ID FROM $wpdb->users ORDER BY
ID");

foreach ($members_search as $userid) {
     // Check each user ID, check for cap
     if (user_can($userid,  'manage_options')) {
         $members[] = $userid;
     }
}

return $members;

I was just wondering if there is a better way perhaps?


More information about the wp-hackers mailing list