Make WordPress Core


Ignore:
Timestamp:
04/17/2019 02:49:49 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Users: In wp_list_authors(), check for author's post count before getting 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/author-template.php

    r45086 r45235  
    443443    }
    444444    foreach ( $authors as $author_id ) {
     445        $posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0;
     446
     447        if ( ! $posts && $args['hide_empty'] ) {
     448            continue;
     449        }
     450
    445451        $author = get_userdata( $author_id );
    446452
    447         if ( $args['exclude_admin'] && 'admin' == $author->display_name ) {
    448             continue;
    449         }
    450 
    451         $posts = isset( $author_count[ $author->ID ] ) ? $author_count[ $author->ID ] : 0;
    452 
    453         if ( ! $posts && $args['hide_empty'] ) {
     453        if ( $args['exclude_admin'] && 'admin' === $author->display_name ) {
    454454            continue;
    455455        }
Note: See TracChangeset for help on using the changeset viewer.