User Queries
Similar to comment queries, user queries can be used to find individual users, users with specific roles, and other parameters.
Here is a basic User query:
1
$args = array(
2
//
3
);
4
5
// The Query
6
$user_query = new WP_User_Query( $args );
7
8
// User Loop
9
if ( ! empty( $user_query->results ) ) {
10
foreach ( $user_query->results as $user ) {
11
echo '<p>' . $user->display_name . '</p>';
12
}
13
} else {
14
echo 'No users found.';
15
}
Copied!
Note that the user query class may not be available yet if your code runs very early.
Last modified 1yr ago
Copy link