Title: get_users
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_users( array $args = array() ): array

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#wp--skip-link--target)

Retrieves list of users matching criteria.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#see-also)󠁿

 * [WP_User_Query](https://developer.wordpress.org/reference/classes/wp_user_query/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#parameters)󠁿

 `$args`arrayoptional

Arguments to retrieve users. See [WP_User_Query::prepare_query()](https://developer.wordpress.org/reference/classes/wp_user_query/prepare_query/)
for more information on accepted arguments.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#return)󠁿

 array List of users.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#more-information)󠁿

Return value is an array of IDs, stdClass objects, or [WP_User](https://developer.wordpress.org/reference/classes/wp_user/)
objects, depending on the value of the ‘fields‘ parameter.

 * If ‘fields‘ is set to ‘all’ (default), or ‘all_with_meta’, it will return an 
   array of [WP_User](https://developer.wordpress.org/reference/classes/wp_user/)
   objects.
 * If ‘fields‘ is set to an array of [ wp_users](https://codex.wordpress.org/Database_Description#Table:_wp_users)
   table fields, it will return an array of stdClass objects with only those fields.
 * If ‘fields‘ is set to any individual [ wp_users](https://codex.wordpress.org/Database_Description#Table:_wp_users)
   table field, an array of IDs will be returned.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#source)󠁿

    ```php
    function get_users( $args = array() ) {

    	$args                = wp_parse_args( $args );
    	$args['count_total'] = false;

    	$user_search = new WP_User_Query( $args );

    	return (array) $user_search->get_results();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/user.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/user.php#L874)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/user.php#L874-L882)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_User_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_user_query/__construct/)`wp-includes/class-wp-user-query.php` |

Constructor.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  |

| Used by | Description | 
| [wp_list_users()](https://developer.wordpress.org/reference/functions/wp_list_users/)`wp-includes/user.php` |

Lists all the users of the site, with several options available.

  | 
| [_build_block_template_result_from_post()](https://developer.wordpress.org/reference/functions/_build_block_template_result_from_post/)`wp-includes/block-template-utils.php` |

Builds a unified template object based a post Object.

  | 
| [wp_uninitialize_site()](https://developer.wordpress.org/reference/functions/wp_uninitialize_site/)`wp-includes/ms-site.php` |

Runs the uninitialization routine for a given site.

  | 
| [populate_network_meta()](https://developer.wordpress.org/reference/functions/populate_network_meta/)`wp-admin/includes/schema.php` |

Creates WordPress network meta and sets the default values.

  | 
| [wpmu_delete_blog()](https://developer.wordpress.org/reference/functions/wpmu_delete_blog/)`wp-admin/includes/ms.php` |

Deletes a site.

  | 
| [wp_ajax_autocomplete_user()](https://developer.wordpress.org/reference/functions/wp_ajax_autocomplete_user/)`wp-admin/includes/ajax-actions.php` |

Handles user autocomplete via AJAX.

  | 
| [confirm_delete_users()](https://developer.wordpress.org/reference/functions/confirm_delete_users/)`wp-admin/includes/ms.php` |  | 
| [wp_dropdown_users()](https://developer.wordpress.org/reference/functions/wp_dropdown_users/)`wp-includes/user.php` |

Creates dropdown HTML content of users.

  | 
| [wp_list_authors()](https://developer.wordpress.org/reference/functions/wp_list_authors/)`wp-includes/author-template.php` |

Lists all the authors of the site, with several options available.

  | 
| [wp_xmlrpc_server::wp_getAuthors()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_getauthors/)`wp-includes/class-wp-xmlrpc-server.php` |

Retrieves authors list.

  | 
| [wp_xmlrpc_server::wp_getUsers()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/wp_getusers/)`wp-includes/class-wp-xmlrpc-server.php` |

Retrieves users.

  |

[Show 6 more](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 8 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-3697)
 2.    [growthwp](https://profiles.wordpress.org/growthwp/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-3697)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-3697)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-3697)
 4.  Please note that if you search by `meta_value` and it ends up being `”` (an empty
     string), the query, which is really a wrap over the `[WP_User_Query](https://developer.wordpress.org/reference/classes/wp_user_query/)`
     class and hence this applies to other functions as well, **ends up forfeiting 
     the check for the `meta_value` and simply downgrades to searching by `meta_key`
     only.**
 5.  Please be very careful when you have `meta_values` that are dynamic or that you
     can’t/don’t check for this exact case, if the list that you retrieve using this
     query is used for something important, you might end up with security holes.
 6.  _“User input should be parsed”._ Yes, but, user input should not be immediately`
     esc_html`’d or the like, escape at output, sanitize before queries and now that
     we know this, check for validity — but here lies the problem, we, as well as some
     people who’ve been with WP for 10+ years didn’t know about this behavior. A `preg_match`
     fixes it all, yes, but only if your assumptions are updated with this knowledge.
 7.  Additionally, this is not a case of “you just forgot to parse”, we parse everything
     that comes inside and had security audits on our core codebase pieces but just
     simply weren’t aware of this behavior and assumed we didn’t even need to parse.
 8.  I’ve opened a ticket about it if you’re interested in a PoC and how it affected
     us specifically: [https://core.trac.wordpress.org/ticket/49641](https://core.trac.wordpress.org/ticket/49641)
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D3697%23feedback-editor-3697)
 10.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-2112)
 11.   [crmunro](https://profiles.wordpress.org/crmunro/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-2112)
 12. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-2112)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-2112)
 13. An example of fetching users that match any one of an array of roles using `role__in`.
 14.     ```php
         <?php
         $blogusers = get_users( array( 'role__in' => array( 'author', 'subscriber' ) ) );
         // Array of WP_User objects.
         foreach ( $blogusers as $user ) {
             echo '<span>' . esc_html( $user->display_name ) . '</span>';
         }
         ```
     
 15.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D2112%23feedback-editor-2112)
 16.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-505)
 17.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-505)
 18. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-505)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-505)
 19. An example using the ‘search’ field.
 20.     ```php
         <?php
         $blogusers = get_users( array( 'search' => 'john' ) );
         // Array of WP_User objects.
         foreach ( $blogusers as $user ) {
         	echo '<span>' . esc_html( $user->user_email ) . '</span>';
         }
         ```
     
 21. 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 would
     pass something like “jo*”.
 22. 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.
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D505%23feedback-editor-505)
 24.  [Skip to note 11 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-5844)
 25.   [Pepro Dev. Group](https://profiles.wordpress.org/peprodev/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-5844)
 26. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-5844)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-5844)
 27. [WP_User_Query](https://developer.wordpress.org/reference/classes/wp_user_query/)
     now accepts fields options in **WordPress 6.0 **
      [https://make.wordpress.org/core/2022/04/29/wp_user_query-now-accepts-fields-options-in-wordpress-6-0/](https://make.wordpress.org/core/2022/04/29/wp_user_query-now-accepts-fields-options-in-wordpress-6-0/)
 28.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D5844%23feedback-editor-5844)
 29.  [Skip to note 12 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-504)
 30.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-504)
 31. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-504)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-504)
 32. A basic example to display all subscribers in an unordered list.
 33.     ```php
         <?php
         $blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
         // Array of WP_User objects.
         foreach ( $blogusers as $user ) {
         	echo '<span>' . esc_html( $user->user_email ) . '</span>';
         }
         ```
     
 34.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D504%23feedback-editor-504)
 35.  [Skip to note 13 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-506)
 36.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-506)
 37. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-506)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-506)
 38. An example of querying by a specific field.
 39.     ```php
         <?php
         $blogusers = get_users( array( 'fields' => array( 'display_name' ) ) );
         // Array of stdClass objects.
         foreach ( $blogusers as $user ) {
         	echo '<span>' . esc_html( $user->display_name ) . '</span>';
         }
         ```
     
 40.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D506%23feedback-editor-506)
 41.  [Skip to note 14 content](https://developer.wordpress.org/reference/functions/get_users/?output_format=md#comment-content-6196)
 42.   [Kowsar Hossain](https://profiles.wordpress.org/kowsar89/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/get_users/#comment-6196)
 43. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-6196)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%23comment-6196)
 44. The default value of the `number` parameter is -1, which means it lists all the
     users. It can cause performance issues on larger sites, so it should be used with
     caution.
 45.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F%3Freplytocom%3D6196%23feedback-editor-6196)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_users%2F)
before being able to contribute a note or feedback.