We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsWordPressWordPress Administration

WP_User_Query and Multisite

In this article we will be explaining how to use WP_User_Query function to get all users from Multisite WordPress installation. Since we will be using custom code here we will need at least basic programming knowledge.

We can start with example of usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!--?php 
$args = array(
	.
	.
	.
);
 
// The Query
$user_query = new WP_User_Query( $args );
 
// User Loop
if ( !empty( $user_query-&gt;results ) ) {
	foreach ( $user_query-&gt;results as $user ) {
		echo '&lt;p&gt;' . $user-&gt;display_name . '&lt;/p&gt;';
	}
} else {
	echo 'No users found.';
}
?-->

With such code we can perform queries to WordPress database “wp_users” and “wp_usermeta” tables. This method can be useful when we have lots of users created in WordPress websites and would like them to be displayed somewhere. More information about this function can be found by visiting official WordPress class reference.

Rate this Tutorial:
No CommentsLeave a Comment

Other (182)

Popular Keywords