SQL Query to Get list of all users along with their blogs

You can use get_blogs_of_user() to get all the blogs of a given user.

So to get a list sorted by the users:

global $wpdb;
$blogs = array();
$user_ids = $wpdb->get_col( 'SELECT ID FROM $wpdb->users' );
foreach( $user_ids as $user_id ) {
    $blogs[$user_id] = get_blogs_of_user( $user_id );
}
// you can use var_dump( $blogs ); to see what's in the $blogs array

Leave a Comment