WP_User_Query::query()

Execute the query, with the current variables.


Source

File: wp-includes/class-wp-user-query.php

	public function query() {
		global $wpdb;

		$qv =& $this->query_vars;

		$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";

		if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) {
			$this->results = $wpdb->get_results( $this->request );
		} else {
			$this->results = $wpdb->get_col( $this->request );
		}

		/**
		 * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
		 *
		 * @since WP-3.2.0
		 *
		 * @global wpdb $wpdb ClassicPress database abstraction object.
		 *
		 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
		 */
		if ( isset( $qv['count_total'] ) && $qv['count_total'] )
			$this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );

		if ( !$this->results )
			return;

		if ( 'all_with_meta' == $qv['fields'] ) {
			cache_users( $this->results );

			$r = array();
			foreach ( $this->results as $userid )
				$r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );

			$this->results = $r;
		} elseif ( 'all' == $qv['fields'] ) {
			foreach ( $this->results as $key => $user ) {
				$this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] );
			}
		}
	}


Changelog

Changelog
Version Description
WP-3.1.0 Introduced.