Filter by author (drop-down list of authors) in the admin posts table

In this note, we'll look at how to add a new filter by author to the posts table in the admin panel.

The problem is this: There is a site with multiple authors, but no way to filter posts by a specific author. The code below adds a dropdown list filter of posts authors to the posts table in the WordPress admin panel (next to the date and category dropdown lists).

if( is_admin() ){

	add_action( 'restrict_manage_posts', 'wp_posts_list__author_dropdown' );

	function wp_posts_list__author_dropdown( $post_type ){

		if( ! in_array( $post_type, ['page','post'] ) ){
			return;
		}

		wp_dropdown_users( [
			'show_option_all' => 'Все авторы',
			'selected'        => get_query_var( 'author', 0 ),
			'name'            => 'author',
			'who'             => 'authors',
			// 'role__in'        => ['author','editor','administrator'],
		] );
	}
}

We get it:

Drop-down list of authors in the posts table

The code uses a function and a hook:

I recommend to get familiar with their work to better understand what the code does.

Read also: how to add your filters to different tables in the admin: posts, categories, users, comments.