Use DISTINCT to eliminate duplicates when using an OR meta query relation. Props scribu, greuben. fixes #17582

git-svn-id: https://develop.svn.wordpress.org/trunk@18178 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2011-06-07 15:55:05 +00:00
parent 6025531032
commit efb682a641
1 changed files with 9 additions and 2 deletions

View File

@ -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;