wp_dropdown_users()
Create dropdown HTML content of users.
The content can either be displayed, which it is by default, or retrieved by setting the 'echo' argument to false. The 'include' and 'exclude' arguments are optional; if they are not specified, all users will be displayed. Only one can be used in a single call, either 'include' or 'exclude', but not both.
Hooks from the function
Returns
String
. HTML dropdown list of users.
Usage
wp_dropdown_users( $args );
- $args(array|string)
Array or string of arguments to generate a drop-down of users. See WP_User_Query::prepare_query() for additional available arguments.
Default: ''
-
show_option_all(string)
Text to show as the drop-down default (all).
Default: '' -
show_option_none(string)
Text to show as the drop-down default when no users were found.
Default: '' -
option_none_value(int|string)
Value to use for $show_option_none when no users were found.
Default: -1 -
hide_if_only_one_author(string)
Whether to skip generating the drop-down if only one user was found.
Default: '' -
orderby(string)
Field to order found users by. Accepts user fields.
Default: 'display_name' -
order(string)
Whether to order users in ascending or descending order. Accepts 'ASC' (ascending) or 'DESC' (descending).
Default: 'ASC' -
include(int[]|string)
Array or comma-separated list of user IDs to include.
Default: '' -
exclude(int[]|string)
Array or comma-separated list of user IDs to exclude.
Default: '' -
multi(true|false|int)
Whether to skip the ID attribute on the 'select' element. Accepts 1|true or 0|false.
Default: 0|false -
show(string)
User data to display. If the selected item is empty then the 'user_login' will be displayed in parentheses. Accepts any user field, or 'display_name_with_login' to show the display name with user_login in parentheses.
Default: 'display_name' -
echo(int|true|false)
Whether to echo or return the drop-down. Accepts 1|true (echo) or 0|false (return).
Default: 1|true -
selected(int)
Which user ID should be selected. -
include_selected(true|false)
Whether to always include the selected user ID in the drop- down.
Default: false -
name(string)
Name attribute of select element.
Default: 'user' -
id(string)
ID attribute of the select element.
Default: value of $name -
class(string)
Class attribute of the select element.
Default: '' -
blog_id(int)
ID of blog (Multisite only).
Default: ID of the current blog -
who(string)
Deprecated, use $capability instead. Which type of users to query. Accepts only an empty string or 'authors'.
Default: empty (all users) -
role(string|string[])
An array or a comma-separated list of role names that users must match to be included in results. Note that this is an inclusive list: users must match each role.
Default: '' -
role__in(string[])
An array of role names. Matched users must have at least one of these roles.
Default: empty array -
role__not_in(string[])
An array of role names to exclude. Users matching one or more of these roles will not be included in results.
Default: empty array -
capability(string|string[])
An array or a comma-separated list of capability names that users must match to be included in results. Note that this is an inclusive list: users must match each capability. Does NOT work for capabilities not in the database or filtered via {@see 'map_meta_cap'}.
Default: '' -
capability__in(string[])
An array of capability names. Matched users must have at least one of these capabilities. Does NOT work for capabilities not in the database or filtered via {@see 'map_meta_cap'}.
Default: empty array - capability__not_in(string[])
An array of capability names to exclude. Users matching one or more of these capabilities will not be included in results. Does NOT work for capabilities not in the database or filtered via {@see 'map_meta_cap'}.
Default: empty array
-
Examples
#1 Display a drop-down list of all users
Let's turn it into a full-fledged data submission form (inside the <form> tag and with a submit button):
<h2>Users:</h2> <form action="<?php bloginfo('url'); ?>" method="get"> <?php wp_dropdown_users( [ 'name'=>'author' ] ); ?> <input type="submit" name="submit" value="view" /> </form>
#2 Drop-down list of authors in the posts table
See separate note.
#3 The who
argument is no longer valid
Since version 5.9, you’ll need to use the new capabilities
or role
argument:
Changelog
Since 2.3.0 | Introduced. |
Since 4.5.0 | Added the 'display_name_with_login' value for 'show'. |
Since 4.7.0 | Added the 'role', 'role__in', and 'role__not_in' parameters. |
Since 5.9.0 | Added the 'capability', 'capability__in', and 'capability__not_in' parameters. Deprecated the 'who' parameter. |