Skip to content

Commit

Permalink
Users: In wp_list_authors(), check for author's post count before g…
Browse files Browse the repository at this point in the history
…etting author's metadata.

This significantly reduces the number of SQL queries when `wp_list_authors()` is called on a site where the majority of users don't have any posts, e.g. a membership site.

Props billerickson, ianbelanger, dswebsme.
Fixes #45105.

git-svn-id: https://develop.svn.wordpress.org/trunk@45235 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Apr 17, 2019
1 parent 60fd53e commit 774dcea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/wp-includes/author-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,15 @@ function wp_list_authors( $args = '' ) {
$author_count[ $row->post_author ] = $row->count;
}
foreach ( $authors as $author_id ) {
$author = get_userdata( $author_id );
$posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0;

if ( $args['exclude_admin'] && 'admin' == $author->display_name ) {
if ( ! $posts && $args['hide_empty'] ) {
continue;
}

$posts = isset( $author_count[ $author->ID ] ) ? $author_count[ $author->ID ] : 0;
$author = get_userdata( $author_id );

if ( ! $posts && $args['hide_empty'] ) {
if ( $args['exclude_admin'] && 'admin' === $author->display_name ) {
continue;
}

Expand Down

0 comments on commit 774dcea

Please sign in to comment.