wp_list_users()
Outputs/gets a list of users' display names from the site in a simple or LI list format. A number of parameters can be specified for selection.
Hooks from the function
Returns
String|null.
- When
$echo = true(by default) - Outputs HTML code to the screen and returns null. - When
$echo = false- returns HTML code.
Usage Template
<?php wp_list_users( [ 'orderby' => 'name', 'order' => 'ASC', 'number' => '', 'exclude_admin' => true, 'show_fullname' => false, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '', ] ); ?>
Usage
wp_list_users( $args );
- $args(string|array)
Array or string of arguments for selection.
Default: array()
-
orderby(string)
How to sort users. Can be:nicename email url registered user_nicename user_email user_url user_registered name display_name post_count ID meta_value user_login
Default: 'name'
-
order(string)
Sorting direction for $orderby. Can be:ASC,DESC.
Default: 'ASC' -
number(int)
The maximum number of users that the function will retrieve.
Default: 0 (all users) -
exclude_admin(true|false)
Whether to exclude administrators - the 'admin' account.
Default: false -
show_fullname(true|false)
Whether to show the user's full name. By default, display_name is shown. If this parameter is enabled, a combination offirst_name last_namewill be shown only if these fields are filled in for the user; otherwise, display_name will be shown.
Default: false -
feed(string)
If not empty, show a link to the user's feed and use the text specified in this parameter as the anchor text for the link. If a URL is specified in feed_image, the text of this parameter will be specified in the alt attribute of the feed link.
Default: '' -
feed_image(string)
If not empty, show an IMG as the anchor for the feed link. The URL specified here is a link to the image.
Default: '' -
feed_type(string)
The type of feed to link to, for example 'rss2'.
Default: default feed type -
echo(true|false)
Whether to output the result or return it.
Default: true -
style(string)
If 'list', each user will be wrapped in a<li>element; otherwise, users will be separated by commas.
Default: 'list' -
html(true|false)
Whether to output the list items in HTML form or as plain text. If false is specified, all parameters that imply HTML markup will stop working - this includes feed, feed_image, list.
Default: true -
exclude(string|array)
Array of user IDs to exclude from the list. Can be specified as a string where IDs are separated by spaces or commas.
Default: '' - include(string|array)
Array of user IDs to show in the list. Can be specified as a string where IDs are separated by spaces or commas.
Default: ''
-
Examples
#1 Demo of what the function outputs
$users_list = wp_list_users( [ 'number' => 3, 'echo' => false, 'style' => 'list', ] ); echo htmlspecialchars( $users_list ); /* style => 'list': <li>Wasija</li> <li>stas</li> <li>anastasiiik</li> */ /* style => '' or 'html' => false: Wasija, stas, anastasiiik */
Changelog
| Since 5.9.0 | Introduced. |