get_users()获取所有的用户信息(可筛选)

目录

描述

Wrapper for WP_User_Query. Retrieves an array of users matching the criteria given in $args.

get_users() 描述

用法

 <?php get_users$args ); ?> 

get_users() 用法

参数

  • blog_id - The current blog's ID, unless multisite is enabled and another ID is provided
  • role - Limit the returned users to the role specified.
  • include - An array of IDs. Only users matching these IDs will be returned. Note that at present the include and exclude (below) arguments cannot be used together. See ticket #23228
  • exclude - An array of IDs. Users matching these IDs will not be returned, regardless of the other arguments. It will be ignored if the include argument is set.
  • meta_key - The meta_key in the wp_usermeta table for the meta_value to be returned. See get_userdata() for the possible meta keys.
  • meta_value - The value of the meta key.
  • meta_compare - Operator to test the 'meta_value'. Possible values are '!=', '>', '>=', '<', or '<='. Default value is '='.
  • meta_query - An array that is handled through to the WP_Meta_Query object.
  • date_query - An array that is handled through to the WP_Date_Query object. Date queries are allowed for the user_registered field.
  • orderby - Sort by 'ID', 'login', 'nicename', 'email', 'url', 'registered', 'display_name', 'post_count', or 'meta_value' (query must also contain a 'meta_key' - see WP_User_Query).
  • order - ASC (ascending) or DESC (descending).
  • offset - The first n users to be skipped in the returned array.
  • search - Use this argument to search users by email address, URL, ID, username or display_name.
  • number - Limit the total number of users returned.
  • count_total - This is always false. To get a total count, call WP_User_Query directly instead. See here for usage.
  • fields - Which fields to include in the returned array. Default is 'all'. Pass an array of wp_users table fields to return an array of stdClass objects with only those fields.
  • who - If set to 'authors', only authors (user level greater than 0) will be returned.

get_users() 参数

示例

A basic example to display all subscribers in an unordered list.

An example using the 'search' field.

The first example will find and display all users that have a user name, ID, email of "john". You can also do wild card search by adding an * before or after your search query. For example, to search for all users that start with "jo", you would pass something like "jo*".

The results will be all users whose user names, IDs, or emails that start with "jo". The * can be placed before or after your search query. When placed before, the results will be all users that end in your query.

An example of querying by a specific field.

get_users() 示例

注意

get_users() 注意