WordPress.org

Make WordPress Core

Ticket #17582: 17582.3.diff

File 17582.3.diff, 1.6 KB (added by greuben, 7 years ago)
  • wp-includes/user.php

     
    360360        var $query_where;
    361361        var $query_orderby;
    362362        var $query_limit;
     363        var $query_groupby = '';
    363364
    364365
    365366        /**
     
    517518                        $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
    518519                        $this->query_from .= $clauses['join'];
    519520                        $this->query_where .= $clauses['where'];
     521                        $this->query_groupby = 'group by ID';
    520522                }
    521523
    522524                if ( !empty( $qv['include'] ) ) {
     
    540542                global $wpdb;
    541543
    542544                if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) {
    543                         $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     545                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_groupby $this->query_orderby $this->query_limit");
    544546                } else {
    545                         $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     547                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_groupby $this->query_orderby $this->query_limit");
    546548                }
    547549
    548550                if ( $this->query_vars['count_total'] )
    549                         $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where");
     551                        $this->total_users = $wpdb->get_var("SELECT COUNT(DISTINCT ID) $this->query_from $this->query_where");
    550552
    551553                if ( !$this->results )
    552554                        return;