apply_filters( 'wp_dropdown_users_args', array $query_args, array $parsed_args )

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


Parameters

$query_args array
The query arguments for get_users() .
More Arguments from get_users( ... $args ) Array or string of Query parameters.
  • blog_id int
    The site ID. Default is the current site.
  • 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.
  • role__in string[]
    An array of role names. Matched users must have at least one of these roles.
  • 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.
  • meta_key string|string[]
    Meta key or keys to filter by.
  • meta_value string|string[]
    Meta value or values to filter by.
  • meta_compare string
    MySQL operator used for comparing the meta value.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_compare_key string
    MySQL operator used for comparing the meta key.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_type string
    MySQL data type that the meta_value column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_type_key string
    MySQL data type that the meta_key column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_query array
    An associative array of WP_Meta_Query arguments.
    See WP_Meta_Query::__construct() for accepted values.
  • 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'.
  • 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'.
  • 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'.
  • include int[]
    An array of user IDs to include.
  • exclude int[]
    An array of user IDs to exclude.
  • search string
    Search keyword. Searches for possible string matches on columns.
    When $search_columns is left empty, it tries to determine which column to search in based on search string.
  • search_columns string[]
    Array of column names to be searched. Accepts 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename', 'display_name'.
  • orderby string|array
    Field(s) to sort the retrieved users by. May be a single value, an array of values, or a multi-dimensional array with fields as keys and orders ('ASC' or 'DESC') as values. Accepted values are:
    • 'ID'
    • 'display_name' (or 'name')
    • 'include'
    • 'user_login' (or 'login')
    • 'login__in'
    • 'user_nicename' (or 'nicename'),
    • 'nicename__in'
    • 'user_email (or 'email')
    • 'user_url' (or 'url'),
    • 'user_registered' (or 'registered')
    • 'post_count'
    • 'meta_value',
    • 'meta_value_num'
    • The value of $meta_key
    • An array key of $meta_query To use 'meta_value' or 'meta_value_num', $meta_key must be also be defined. Default 'user_login'.
  • order string
    Designates ascending or descending order of users. Order values passed as part of an $orderby array take precedence over this parameter. Accepts 'ASC', 'DESC'. Default 'ASC'.
  • offset int
    Number of users to offset in retrieved results. Can be used in conjunction with pagination. Default 0.
  • number int
    Number of users to limit the query for. Can be used in conjunction with pagination. Value -1 (all) is supported, but should be used with caution on larger sites.
    Default -1 (all users).
  • paged int
    When used with number, defines the page of results to return.
    Default 1.
  • count_total bool
    Whether to count the total number of users found. If pagination is not needed, setting this to false can improve performance.
    Default true.
  • fields string|string[]
    Which fields to return. Single or all fields (string), or array of fields. Accepts:
    • 'ID'
    • 'display_name'
    • 'user_login'
    • 'user_nicename'
    • 'user_email'
    • 'user_url'
    • 'user_registered'
    • 'user_pass'
    • 'user_activation_key'
    • 'user_status'
    • 'spam' (only available on multisite installs)
    • 'deleted' (only available on multisite installs)
    • 'all' for all fields and loads user meta.
    • 'all_with_meta' Deprecated. Use 'all'.
    Default 'all'.
  • who string
    Type of users to query. Accepts 'authors'.
    Default empty (all users).
  • has_published_posts bool|string[]
    Pass an array of post types to filter results to users who have published posts in those post types. true is an alias for all public post types.
  • nicename string
    The user nicename.
  • nicename__in string[]
    An array of nicenames to include. Users matching one of these nicenames will be included in results.
  • nicename__not_in string[]
    An array of nicenames to exclude. Users matching one of these nicenames will not be included in results.
  • login string
    The user login.
  • login__in string[]
    An array of logins to include. Users matching one of these logins will be included in results.
  • login__not_in string[]
    An array of logins to exclude. Users matching one of these logins will not be included in results.
$parsed_args array
The arguments passed to wp_dropdown_users() combined with the defaults.
More Arguments from wp_dropdown_users( ... $args ) Array or string of Query parameters.
  • blog_id int
    The site ID. Default is the current site.
  • 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.
  • role__in string[]
    An array of role names. Matched users must have at least one of these roles.
  • 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.
  • meta_key string|string[]
    Meta key or keys to filter by.
  • meta_value string|string[]
    Meta value or values to filter by.
  • meta_compare string
    MySQL operator used for comparing the meta value.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_compare_key string
    MySQL operator used for comparing the meta key.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_type string
    MySQL data type that the meta_value column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_type_key string
    MySQL data type that the meta_key column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_query array
    An associative array of WP_Meta_Query arguments.
    See WP_Meta_Query::__construct() for accepted values.
  • 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'.
  • 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'.
  • 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'.
  • include int[]
    An array of user IDs to include.
  • exclude int[]
    An array of user IDs to exclude.
  • search string
    Search keyword. Searches for possible string matches on columns.
    When $search_columns is left empty, it tries to determine which column to search in based on search string.
  • search_columns string[]
    Array of column names to be searched. Accepts 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename', 'display_name'.
  • orderby string|array
    Field(s) to sort the retrieved users by. May be a single value, an array of values, or a multi-dimensional array with fields as keys and orders ('ASC' or 'DESC') as values. Accepted values are:
    • 'ID'
    • 'display_name' (or 'name')
    • 'include'
    • 'user_login' (or 'login')
    • 'login__in'
    • 'user_nicename' (or 'nicename'),
    • 'nicename__in'
    • 'user_email (or 'email')
    • 'user_url' (or 'url'),
    • 'user_registered' (or 'registered')
    • 'post_count'
    • 'meta_value',
    • 'meta_value_num'
    • The value of $meta_key
    • An array key of $meta_query To use 'meta_value' or 'meta_value_num', $meta_key must be also be defined. Default 'user_login'.
  • order string
    Designates ascending or descending order of users. Order values passed as part of an $orderby array take precedence over this parameter. Accepts 'ASC', 'DESC'. Default 'ASC'.
  • offset int
    Number of users to offset in retrieved results. Can be used in conjunction with pagination. Default 0.
  • number int
    Number of users to limit the query for. Can be used in conjunction with pagination. Value -1 (all) is supported, but should be used with caution on larger sites.
    Default -1 (all users).
  • paged int
    When used with number, defines the page of results to return.
    Default 1.
  • count_total bool
    Whether to count the total number of users found. If pagination is not needed, setting this to false can improve performance.
    Default true.
  • fields string|string[]
    Which fields to return. Single or all fields (string), or array of fields. Accepts:
    • 'ID'
    • 'display_name'
    • 'user_login'
    • 'user_nicename'
    • 'user_email'
    • 'user_url'
    • 'user_registered'
    • 'user_pass'
    • 'user_activation_key'
    • 'user_status'
    • 'spam' (only available on multisite installs)
    • 'deleted' (only available on multisite installs)
    • 'all' for all fields and loads user meta.
    • 'all_with_meta' Deprecated. Use 'all'.
    Default 'all'.
  • who string
    Type of users to query. Accepts 'authors'.
    Default empty (all users).
  • has_published_posts bool|string[]
    Pass an array of post types to filter results to users who have published posts in those post types. true is an alias for all public post types.
  • nicename string
    The user nicename.
  • nicename__in string[]
    An array of nicenames to include. Users matching one of these nicenames will be included in results.
  • nicename__not_in string[]
    An array of nicenames to exclude. Users matching one of these nicenames will not be included in results.
  • login string
    The user login.
  • login__in string[]
    An array of logins to include. Users matching one of these logins will be included in results.
  • login__not_in string[]
    An array of logins to exclude. Users matching one of these logins will not be included in results.

Top ↑

Source

File: wp-includes/user.php. View all references

$query_args = apply_filters( 'wp_dropdown_users_args', $query_args, $parsed_args );


Top ↑

Changelog

Changelog
Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Jonathan Goldford

    This filter allows you to set subscribers as authors of blog posts within the admin without giving them additional privileges. Here’s the code:

    add_filter( 'wp_dropdown_users_args', 'add_subscribers_to_dropdown', 10, 2 );
    function add_subscribers_to_dropdown( $query_args, $r ) {
    
        $query_args['who'] = '';
        return $query_args;
    
    }
  2. Skip to note 2 content
    Contributed by RiseOfLex88

    In addition to Jonathan’s contribution, you can also expand it further by specifying the role. This is undocumented on wp codex. But does work e.g.

    function wpdocs_add_subscribers_to_dropdown( $query_args, $r ) {
     
    	$query_args['role'] = array('contributor');
    
    	// Unset the 'who' as this defaults to the 'author' role
    	unset( $query_args['who'] );
    
    	return $query_args;
    }
    add_filter( 'wp_dropdown_users_args', 'wpdocs_add_subscribers_to_dropdown', 10, 2 );
  3. Skip to note 3 content
    Contributed by pgDarkness

    In addition to RiseOfLex88’s contribution, you can also specify multiple roles.

    function wpdocs_add_subscribers_to_dropdown( $query_args ) {
    
    	// Use this array to specify multiple roles to show in dropdown
        $query_args['role__in'] = array( 'contributor', 'administrator' );
    
    	// Use this array to specify multiple roles to hide in dropdown
        $query_args['role__not_in'] = array( 'editor' );
    
        // Unset the 'who' as this defaults to the 'author' role
        unset( $query_args['who'] );
     
        return $query_args;
    }
    add_filter( 'wp_dropdown_users_args', 'wpdocs_add_subscribers_to_dropdown' );

    If you dump variable “$query_args” inside this function, this is what you will get:

    array(10) { 
      ["blog_id"]=> int(1) 
      ["include"]=> string(0) "" 
      ["exclude"]=> string(0) "" 
      ["orderby"]=> string(12) "display_name" 
      ["order"]=> string(3) "ASC" 
      ["who"]=> string(7) "authors" 
      ["role"]=> string(0) "" 
      ["role__in"]=> array(0) { } 
      ["role__not_in"]=> array(0) { } 
      ["fields"]=> array(3) { 
        [0]=> string(2) "ID" 
        [1]=> string(10) "user_login" 
        [2]=> string(12) "display_name" 
      } 
    }
  4. Skip to note 4 content
    Contributed by Sarah Lewis

    Note that if you’re trying to filter the “Author” dropdown on the post editor screen, and the post editor is using Gutenberg, this filter doesn’t fire. You’ll need to work with the rest_user_query filter instead. (But also note that this filter is used for a lot more than the Author dropdown, so use it thoughtfully.)

You must log in before being able to contribute a note or feedback.