mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Use DISTINCT to eliminate duplicates when using an OR meta query relation. Props scribu, greuben. fixes #17582
git-svn-id: http://svn.automattic.com/wordpress/trunk@18178 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
991dedba6b
commit
1b8b61d1ae
@ -383,7 +383,8 @@ class WP_User_Query {
|
||||
'search' => '',
|
||||
'orderby' => 'login',
|
||||
'order' => 'ASC',
|
||||
'offset' => '', 'number' => '',
|
||||
'offset' => '',
|
||||
'number' => '',
|
||||
'count_total' => true,
|
||||
'fields' => 'all',
|
||||
'who' => ''
|
||||
@ -418,6 +419,9 @@ class WP_User_Query {
|
||||
$this->query_fields = "$wpdb->users.ID";
|
||||
}
|
||||
|
||||
if ( $this->query_vars['count_total'] )
|
||||
$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
|
||||
|
||||
$this->query_from = "FROM $wpdb->users";
|
||||
$this->query_where = "WHERE 1=1";
|
||||
|
||||
@ -517,6 +521,9 @@ class WP_User_Query {
|
||||
$clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
|
||||
$this->query_from .= $clauses['join'];
|
||||
$this->query_where .= $clauses['where'];
|
||||
|
||||
if ( 'OR' == $meta_query->relation )
|
||||
$this->query_fields = 'DISTINCT ' . $this->query_fields;
|
||||
}
|
||||
|
||||
if ( !empty( $qv['include'] ) ) {
|
||||
@ -546,7 +553,7 @@ class WP_User_Query {
|
||||
}
|
||||
|
||||
if ( $this->query_vars['count_total'] )
|
||||
$this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where");
|
||||
$this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
|
||||
|
||||
if ( !$this->results )
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user