具有SQL查询结果列名属性的行对象数组,即wp\\U users表中的指定字段,或者,如果字段等于“all\\u with\\u meta”,则为wp\\U用户对象数组。
字段值默认为“all”,这将返回wp_users table, 但可以通过传递指定字段的数组来覆盖,并按如下方式进行分析:
if ( is_array( $qv[\'fields\'] ) ) {
$qv[\'fields\'] = array_unique( $qv[\'fields\'] );
$this->query_fields = array();
foreach ( $qv[\'fields\'] as $field )
$this->query_fields[] = $wpdb->users . \'.\' . esc_sql( $field );
$this->query_fields = implode( \',\', $this->query_fields );
} elseif ( \'all\' == $qv[\'fields\'] ) {
$this->query_fields = "$wpdb->users.*";
} else {
$this->query_fields = "$wpdb->users.ID";
}
请参见中的查询函数
WP_User_Query class definition - 如果“fields”是“all\\u with\\u meta”,则查询结果将替换为WP\\u用户对象
function query() {
global $wpdb;
if ( is_array( $this->query_vars[\'fields\'] ) || \'all\' == $this->query_vars[\'fields\'] ) {
$this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
} else {
$this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
}
if ( $this->query_vars[\'count_total\'] )
$this->total_users = $wpdb->get_var( apply_filters( \'found_users_query\', \'SELECT FOUND_ROWS()\' ) );
if ( !$this->results )
return;
if ( \'all_with_meta\' == $this->query_vars[\'fields\'] ) {
cache_users( $this->results );
$r = array();
foreach ( $this->results as $userid )
$r[ $userid ] = new WP_User( $userid, \'\', $this->query_vars[\'blog_id\'] );
$this->results = $r;
}
}
最后,这里记录了WP\\U用户对象:
http://codex.wordpress.org/Class_Reference/WP_User定义如下:http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/capabilities.php