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

---

# wp_dropdown_users( array|string $args ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#user-contributed-notes)

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

Creates dropdown HTML content of users.

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

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.

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

 `$args`array|stringoptional

Array or string of arguments to generate a drop-down of users.
 See [WP_User_Query::prepare_query()](https://developer.wordpress.org/reference/classes/wp_user_query/prepare_query/)
for additional available arguments.

 * `show_option_all` string
 * Text to show as the drop-down default (all).
    Default empty.
 * `show_option_none` string
 * Text to show as the drop-down default when no users were found. Default empty.
 * `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 
   empty.
 * `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 empty.
 * `exclude` int[]|string
 * Array or comma-separated list of user IDs to exclude.
    Default empty.
 * `multi` bool|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|bool
 * 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. Default 0.
 * `include_selected` bool
 * 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 is the value of `$name`.
 * `class` string
 * Class attribute of the select element. Default empty.
 * `blog_id` int
 * ID of blog (Multisite only). Default is 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 empty.
 * `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 ['map_meta_cap'](https://developer.wordpress.org/reference/hooks/map_meta_cap/).
   Default empty.
 * `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 ['map_meta_cap'](https://developer.wordpress.org/reference/hooks/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 ['map_meta_cap'](https://developer.wordpress.org/reference/hooks/map_meta_cap/).
   Default empty array.

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

 string HTML dropdown list of users.

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

    ```php
    function wp_dropdown_users( $args = '' ) {
    	$defaults = array(
    		'show_option_all'         => '',
    		'show_option_none'        => '',
    		'hide_if_only_one_author' => '',
    		'orderby'                 => 'display_name',
    		'order'                   => 'ASC',
    		'include'                 => '',
    		'exclude'                 => '',
    		'multi'                   => 0,
    		'show'                    => 'display_name',
    		'echo'                    => 1,
    		'selected'                => 0,
    		'name'                    => 'user',
    		'class'                   => '',
    		'id'                      => '',
    		'blog_id'                 => get_current_blog_id(),
    		'who'                     => '',
    		'include_selected'        => false,
    		'option_none_value'       => -1,
    		'role'                    => '',
    		'role__in'                => array(),
    		'role__not_in'            => array(),
    		'capability'              => '',
    		'capability__in'          => array(),
    		'capability__not_in'      => array(),
    	);

    	$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;

    	$parsed_args = wp_parse_args( $args, $defaults );

    	$query_args = wp_array_slice_assoc(
    		$parsed_args,
    		array(
    			'blog_id',
    			'include',
    			'exclude',
    			'orderby',
    			'order',
    			'who',
    			'role',
    			'role__in',
    			'role__not_in',
    			'capability',
    			'capability__in',
    			'capability__not_in',
    		)
    	);

    	$fields = array( 'ID', 'user_login' );

    	$show = ! empty( $parsed_args['show'] ) ? $parsed_args['show'] : 'display_name';
    	if ( 'display_name_with_login' === $show ) {
    		$fields[] = 'display_name';
    	} else {
    		$fields[] = $show;
    	}

    	$query_args['fields'] = $fields;

    	$show_option_all   = $parsed_args['show_option_all'];
    	$show_option_none  = $parsed_args['show_option_none'];
    	$option_none_value = $parsed_args['option_none_value'];

    	/**
    	 * Filters the query arguments for the list of users in the dropdown.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param array $query_args  The query arguments for get_users().
    	 * @param array $parsed_args The arguments passed to wp_dropdown_users() combined with the defaults.
    	 */
    	$query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $parsed_args );

    	$users = get_users( $query_args );

    	$output = '';
    	if ( ! empty( $users ) && ( empty( $parsed_args['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
    		$name = esc_attr( $parsed_args['name'] );
    		if ( $parsed_args['multi'] && ! $parsed_args['id'] ) {
    			$id = '';
    		} else {
    			$id = $parsed_args['id'] ? " id='" . esc_attr( $parsed_args['id'] ) . "'" : " id='$name'";
    		}
    		$output = "<select name='{$name}'{$id} class='" . $parsed_args['class'] . "'>\n";

    		if ( $show_option_all ) {
    			$output .= "\t<option value='0'>$show_option_all</option>\n";
    		}

    		if ( $show_option_none ) {
    			$_selected = selected( $option_none_value, $parsed_args['selected'], false );
    			$output   .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
    		}

    		if ( $parsed_args['include_selected'] && ( $parsed_args['selected'] > 0 ) ) {
    			$found_selected          = false;
    			$parsed_args['selected'] = (int) $parsed_args['selected'];

    			foreach ( (array) $users as $user ) {
    				$user->ID = (int) $user->ID;
    				if ( $user->ID === $parsed_args['selected'] ) {
    					$found_selected = true;
    				}
    			}

    			if ( ! $found_selected ) {
    				$selected_user = get_userdata( $parsed_args['selected'] );
    				if ( $selected_user ) {
    					$users[] = $selected_user;
    				}
    			}
    		}

    		foreach ( (array) $users as $user ) {
    			if ( 'display_name_with_login' === $show ) {
    				/* translators: 1: User's display name, 2: User login. */
    				$display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
    			} elseif ( ! empty( $user->$show ) ) {
    				$display = $user->$show;
    			} else {
    				$display = '(' . $user->user_login . ')';
    			}

    			$_selected = selected( $user->ID, $parsed_args['selected'], false );
    			$output   .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
    		}

    		$output .= '</select>';
    	}

    	/**
    	 * Filters the wp_dropdown_users() HTML output.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param string $output HTML output generated by wp_dropdown_users().
    	 */
    	$html = apply_filters( 'wp_dropdown_users', $output );

    	if ( $parsed_args['echo'] ) {
    		echo $html;
    	}
    	return $html;
    }
    ```

[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#L1719)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/user.php#L1719-L1864)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_dropdown_users’, string $output )](https://developer.wordpress.org/reference/hooks/wp_dropdown_users/)

Filters the [wp_dropdown_users()](https://developer.wordpress.org/reference/functions/wp_dropdown_users/)
HTML output.

 [apply_filters( ‘wp_dropdown_users_args’, array $query_args, array $parsed_args )](https://developer.wordpress.org/reference/hooks/wp_dropdown_users_args/)

Filters the query arguments for the list of users in the dropdown.

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

| Uses | Description | 
| [selected()](https://developer.wordpress.org/reference/functions/selected/)`wp-includes/general-template.php` |

Outputs the HTML selected attribute.

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

Determines whether the query is for an existing author archive page.

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

Retrieves the value of a query variable in the [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) class.

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

Extracts a slice of an array, given a list of keys.

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

Retrieves list of users matching criteria.

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

Retrieves translated string with gettext context.

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

Escaping for HTML attributes.

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

Escaping for HTML blocks.

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

Retrieves user info by user ID.

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

Retrieves the current site ID.

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

Merges user defined arguments into defaults array.

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

Calls the callback functions that have been added to a filter hook.

  |

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

| Used by | Description | 
| [post_author_meta_box()](https://developer.wordpress.org/reference/functions/post_author_meta_box/)`wp-admin/includes/meta-boxes.php` |

Displays form field with list of authors.

  | 
| [WP_Posts_List_Table::inline_edit()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/inline_edit/)`wp-admin/includes/class-wp-posts-list-table.php` |

Outputs the hidden row displayed when inline editing

  |

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

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `'capability'`, `'capability__in'`, and `'capability__not_in'` parameters.
 Deprecated the `'who'` parameter. | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Added the `'role'`, `'role__in'`, and `'role__not_in'` parameters. | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Added the `'display_name_with_login'` value for `'show'`. | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

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

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#comment-content-758)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_dropdown_users/#comment-758)
 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%2Fwp_dropdown_users%2F%23comment-758)
     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%2Fwp_dropdown_users%2F%23comment-758)
 4.  **Dropdown with Submit Button**
      Displays a users drop-down list in HTML form 
     with a submit button.
 5.      ```php
         <li id="users">
         	<h2><?php esc_html_e( 'users:' ); ?></h2>
         	<form action="<?php home_url(); ?>" method="get">
         		<?php wp_dropdown_users( array( 'name' => 'author' ) ); ?>
         		<input type="submit" name="submit" value="view" />
         	</form>
         </li>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_users%2F%3Freplytocom%3D758%23feedback-editor-758)
 7.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#comment-content-1758)
 8.    [minimamente](https://profiles.wordpress.org/minimamente/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_dropdown_users/#comment-1758)
 9.  [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%2Fwp_dropdown_users%2F%23comment-1758)
     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%2Fwp_dropdown_users%2F%23comment-1758)
 10. **Query users by role (that work):**
 11.     ```php
         $query_users_ids_by_role = [
         	'fields' =&gt; ['id'],
         	'role' =&gt; $role
         ];
     
         $array_of_users = get_users( $query_users_ids_by_role );
     
         $array_of_users_ids = array_map(function ($user) {
         	return $user-&gt;id;
         }, $array_of_users);
     
         $users_ids_list = implode( ',', $array_of_users_ids );
     
         $query_for_dropdown = [
         	'show_option_all'   =&gt; __('All users'),
         	'orderby'           =&gt; 'display_name',
         	'order'             =&gt; 'ASC',
         	'include'           =&gt; $users_ids_list
         ];
     
         wp_dropdown_users($query_for_dropdown);
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_users%2F%3Freplytocom%3D1758%23feedback-editor-1758)
 13.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#comment-content-5646)
 14.   [Stephen](https://profiles.wordpress.org/dropstr/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/wp_dropdown_users/#comment-5646)
 15. [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%2Fwp_dropdown_users%2F%23comment-5646)
     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%2Fwp_dropdown_users%2F%23comment-5646)
 16. The ‘`who`‘ argument is no longer valid since version 5.9, you’ll need to use 
     the new capabilities or role argument:
 17. [New Capability Queries in WordPress 5.9](https://make.wordpress.org/core/2022/01/05/new-capability-queries-in-wordpress-5-9/)
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_users%2F%3Freplytocom%3D5646%23feedback-editor-5646)
 19.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/wp_dropdown_users/?output_format=md#comment-content-1588)
 20.   [Mike Ritter](https://profiles.wordpress.org/ritterml/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_dropdown_users/#comment-1588)
 21. [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%2Fwp_dropdown_users%2F%23comment-1588)
     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%2Fwp_dropdown_users%2F%23comment-1588)
 22. **Query users by role:**
 23.     ```php
         $role = 'subscriber';
     
         $query_users_ids_by_role = array(
         	'field' => 'id',
         	'role' => $role
         );
     
         $array_of_users_ids = get_users( $query_users_ids_by_role );
     
         $users_ids_list = implode( ',',$array_of_users_ids );
     
         $query_for_dropdown = array(
             'include' => $user_ids_list,
         );
     
         wp_dropdown_users( $query_for_dropdown );
         ```
     
 24. * Accumulated from others’ work too.
 25.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_users%2F%3Freplytocom%3D1588%23feedback-editor-1588)

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