Codex tools: Log in
Contents |
Retrieves an array of users matching the criteria given in $args.
<?php get_users( $args ); ?>
<?php $args = array( 'blog_id' => $GLOBALS['blog_id'], 'role' => '', 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'meta_query' => array(), 'include' => array(), 'exclude' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'search' => '', 'number' => '', 'count_total' => false, 'fields' => 'all', 'who' => '' ); ?>
meta_key. However use of meta_keys gives a SQL error.
A basic example to display all subscribers in an unordered list.
<ul>
<?php
$blogusers = get_users('blog_id=1&orderby=nicename&role=subscriber');
foreach ($blogusers as $user) {
echo '<li>' . $user->user_email . '</li>';
}
?>
</ul>
An example using the 'search' field.
<ul>
<?php
$blogusers = get_users('search=john');
foreach ($blogusers as $user) {
echo '<li>' . $user->user_email . '</li>';
}
?>
</ul>
This example will find and display all users that have a user name, ID, email of "john". You can also do wild card search by adding an * before or after your search query. For example, to search for all users that start with "jo", you do this:
<ul>
<?php
$blogusers = get_users('search=jo*');
foreach ($blogusers as $user) {
echo '<li>' . $user->user_email . '</li>';
}
?>
</ul>
The results will be all users whose user names, IDs, or emails that start with "jo". The * can be placed before or after your search query. When placed before, the results will be all users that end in your query.
Array of objects, except when fields specifies a single field to be returned, then an array of values is returned. If fields is set to all_with_meta, it will return an array of WP_User objects.
[ID] => 1 [user_login] => admin [user_pass] => $P$Bxudi6gJMk2GRt2ed3xvZ06c1BPZXi/ [user_nicename] => admin [user_email] => admin@host.com [user_url] => http://localhost/ [user_registered] => 2010-06-29 07:08:55 [user_activation_key] => [user_status] => 0 [display_name] => Richard Branson
0 => Richard Branson 1 => Winston Churchill
get_users() is located in wp-includes/user.php.