Created
February 24, 2015 16:43
-
-
Save JudeRosario/b26152b7acd8c9a74e4f to your computer and use it in GitHub Desktop.
WP Multisite list sites by user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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