From 1b8b61d1ae66341f56b9998d2ae604b28cf1763e Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 7 Jun 2011 15:55:05 +0000 Subject: [PATCH] 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 --- wp-includes/user.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index b773496df..af7f5de57 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -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;