Ticket #1659: 1659.diff

File 1659.diff, 1.5 KB (added by rob1n, 5 years ago)

Patch refreshed and refined.

  • wp-includes/author-template.php

     
    173173} 
    174174 
    175175function wp_list_authors($args = '') { 
     176        global $wpdb; 
     177         
    176178        if ( is_array($args) ) 
    177179                $r = &$args; 
    178180        else 
     
    182184                'feed' => '', 'feed_image' => ''); 
    183185        $r = array_merge($defaults, $r); 
    184186        extract($r); 
    185  
    186         global $wpdb; 
     187         
    187188        // TODO:  Move select to get_authors(). 
    188         $query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"; 
    189         $authors = $wpdb->get_results($query); 
     189        $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"); 
     190         
     191        $author_count = array(); 
     192        foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt <'".current_time('mysql','1')."' GROUP BY post_author") as $row) { 
     193                $author_count[$row->post_author] = $row->count; 
     194        } 
    190195 
    191196        foreach ( (array) $authors as $author ) { 
    192197                $author = get_userdata( $author->ID ); 
    193                 $posts = get_usernumposts($author->ID); 
     198                $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 
    194199                $name = $author->nickname; 
    195200 
    196201                if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )