is_multi_author()WP 3.2.0

Does this site have more than one author

Checks to see if more than one author has published posts.

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

Hooks from the function

Return

true|false. Whether or not we have more than one author

Usage

is_multi_author();

Examples

0

#1 Display a link to the author's posts only if there is more than one author on the site:

if( is_multi_author() ){
	 the_author();
}
0

#2 Add body_class specifying that there is more then one author on the site

Adds a class of group-blog in body tag for site with more than one author (there are several posts with different authors).

add_filter( 'body_class', 'wpdocs_body_classes' );

function wpdocs_body_classes( $classes ) {

	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	return $classes;
}

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 3.2.0 Introduced.

is_multi_author() code WP 6.7.2

function is_multi_author() {
	global $wpdb;

	$is_multi_author = get_transient( 'is_multi_author' );
	if ( false === $is_multi_author ) {
		$rows            = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2" );
		$is_multi_author = 1 < count( $rows ) ? 1 : 0;
		set_transient( 'is_multi_author', $is_multi_author );
	}

	/**
	 * Filters whether the site has more than one author with published posts.
	 *
	 * @since 3.2.0
	 *
	 * @param bool $is_multi_author Whether $is_multi_author should evaluate as true.
	 */
	return apply_filters( 'is_multi_author', (bool) $is_multi_author );
}