Retrieves an array of users matching the criteria given in args
Syntax
:
XHTML
1
2
3
4
5
6
[query.get_users
role="role_name"
orderby="field_name"
order="ASC/DESC"
set=template.user
/]
Input Parameters
:
include (array) – List of users to be included.
exclude (array) – List of users to be excluded.
blog_id (int) – The blog id on a multisite environment. Defaults to the current blog id.
search (string) – Searches for possible string matches on columns. Use of the * wildcard before and/or after the string will match on columns starting with*, *ending with, or *containing* the string you enter.
number (int) – The maximum returned number of results (needed in pagination).
offset (int) – Offset the returned results (needed in pagination).
orderby (string) – Sort retrieved users by parameter. Defaults to ‘login’.
‘ID‘ – Order by user id.
‘display_name‘ – Order by user display name.
‘name‘ / ‘user_name‘ – Order by user name.
‘include‘ – Order by the included list of user_ids (requires the include parameter)
‘login‘ / ‘user_login‘ – Order by user login.
‘nicename‘ / ‘user_nicename‘ – Order by user nicename.
‘email‘ / ‘user_email‘ – Order by user email.
‘url‘ / ‘user_url‘ – Order by user url.
‘registered‘ / ‘user_registered‘ – Order by user registered date.
‘post_count‘ – Order by user post count.
‘meta_value‘ – Note that a ‘meta_key=keyname’ must also be present in the query
‘meta_value_num‘ – Note that a ‘meta_key=keyname’ must also be present in the query
order (string) – Designates the ascending or descending order of the ‘orderby‘ parameter. Defaults to ‘ASC’.
‘ASC‘ – ascending order from lowest to highest values (1, 2, 3; a, b, c).
‘DESC‘ – descending order from highest to lowest values (3, 2, 1; c, b, a).
meta_key (string) – Custom field key.
meta_value (string) – Custom field value.
meta_compare (string) – Operator to test the ‘meta_value‘.
who (string) – Which users to query. Currently only ‘authors’ is supported. Default is all users.
count_total (boolean) – Whether to count the total number of users found. When true (default), the total number of results for the query can be retrieved using the get_total() method. If you don’t need the total number of results, set this to false
fields
(string|array) – Which fields to return. Defaults to all.
‘ID‘ – Return an array of user id’s.
‘display_name‘ – Return an array of user display names.
‘login‘ / ‘user_login‘ – Return an array of user login names.
‘nicename‘ / ‘user_nicename‘ – Return an array of user nicenames.
‘email‘ / ‘user_email‘ – Return an array of user emails.
‘url‘ / ‘user_url‘ – Return an array of user urls.
‘registered‘ / ‘user_registered‘ – Return an array of user registered dates.
‘all (default) or all_with_meta‘ – Returns an array of WP_User objects. Must pass an array to subset fields returned. *’all_with_meta’ currently returns the same fields as ‘all’ which does not include user fields stored in wp_usermeta. You must create a second query to get the user meta fields by ID or use the __get PHP magic method to get the values of these fields.
Return Value
:
It returns:
It returns: An array of IDs, stdClass objects, or WP_User objects, depending on the value of the ‘fields’ parameter
Example 1
:
Code
:
XHTML
1
2
3
4
5
6
7
8
9
[query.get_users
role="subscriber"
orderby="ID"
order="ASC"
set=template.user
/]
//**thisexamplecontainsfewparameters
whichwasneeded**//
Output
:
Description
:
The above example code will give all user which are in role of “subscriber”.