Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Created February 24, 2015 16:43
Show Gist options
  • Select an option

  • Save JudeRosario/b26152b7acd8c9a74e4f to your computer and use it in GitHub Desktop.

Select an option

Save JudeRosario/b26152b7acd8c9a74e4f to your computer and use it in GitHub Desktop.
WP Multisite list sites by user
// The user ID whose sites to display
$queried_user_id = '1' ;
// Select the list of valid Blogs you want to filter from
$site_args = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
// Array of valid sites
$sites = wp_get_sites( $site_args ) ;
foreach ($sites as $site) :
// Filter users based on predefined criteria if needed
$user_args = array(
'blog_id' => $site[blog_id],
'role' => '',
'meta_query' => array(),
'include' => array(),
'exclude' => array(),
);
// List of all users
$site_users = get_users( $user_args );
foreach ($site_users as $user) {
// If its selected user then list or else skip
if ( $queried_user_id == $user-ID):
echo '<span>' . esc_html( $site[domain] ) . '</span>';
endif;
}
endforeach ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment