wppaste
WordPress

WP_User_Query

Since
3.1.0
Source
wp-includes/class-wp-user-query.php:17
Core class used for querying users.

Compatibility

WordPress
since 3.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 5

Every hook that fires from inside WP_User_Query, in the order it appears in the class, grouped by the method that fires it.

Properties · 11

$query_varsarraypublic
Query vars, after parsing
$resultsarrayprivate
List of found user IDs.
$total_usersintprivate
Total number of found users for the current query
$meta_queryWP_Meta_Querypublic
Metadata query container.
$requeststringpublic
The SQL query used to fetch matching users.
$compat_fieldsprivate
$query_fieldspublic
$query_frompublic
$query_wherepublic
$query_orderbypublic
$query_limitpublic

Methods · 17

  • __construct()Constructor.
  • fill_query_vars()Fills in missing query variables with default values.
  • prepare_query()Prepares the query variables.
  • query()Executes the query, with the current variables.
  • get()Retrieves query variable.
  • set()Sets query variable.
  • get_search_sql()Used internally to generate an SQL string for searching across multiple columns.
  • get_results()Returns the list of users.
  • get_total()Returns the total number of users for the current query.
  • parse_orderby()Parses and sanitizes 'orderby' keys passed to the user query.
  • generate_cache_key()Generate cache key.
  • parse_order()Parses an 'order' query variable and casts it to ASC or DESC as necessary.
  • __get()Makes private properties readable for backward compatibility.
  • __set()Makes private properties settable for backward compatibility.
  • __isset()Makes private properties checkable for backward compatibility.
  • __unset()Makes private properties un-settable for backward compatibility.
  • __call()Makes private/protected methods readable for backward compatibility.

Source code

#[AllowDynamicProperties]class WP_User_Query { 	/**	 * Query vars, after parsing	 *	 * @since 3.5.0	 * @var array	 */	public $query_vars = array(); 	/**	 * List of found user IDs.	 *	 * @since 3.1.0	 * @var array	 */	private $results; 	/**	 * Total number of found users for the current query	 *	 * @since 3.1.0	 * @var int	 */	private $total_users = 0; 	/**	 * Metadata query container.	 *	 * @since 4.2.0	 * @var WP_Meta_Query	 */	public $meta_query = false; 	/**	 * The SQL query used to fetch matching users.	 *	 * @since 4.4.0	 * @var string	 */	public $request; 	private $compat_fields = array( 'results', 'total_users' ); 	// SQL clauses.	public $query_fields;	public $query_from;	public $query_where;	public $query_orderby;	public $query_limit; 	/**	 * Constructor.	 *	 * @since 3.1.0	 *	 * @param null|string|array $query Optional. The query variables.	 *                                 See WP_User_Query::prepare_query() for information on accepted arguments.	 */	public function __construct( $query = null ) {		if ( ! empty( $query ) ) {			$this->prepare_query( $query );			$this->query();		}	} 	/**	 * Fills in missing query variables with default values.	 *	 * @since 4.4.0	 *	 * @param string|array $args Query vars, as passed to `WP_User_Query`.	 * @return array Complete query variables with undefined ones filled in with defaults.	 */	public static function fill_query_vars( $args ) {		$defaults = array(			'blog_id'             => get_current_blog_id(),			'role'                => '',			'role__in'            => array(),

Changelog

Introduced in 3.1.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.7
Method get_cache_last_changed() added.verified against source
3.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-user-query.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.