Author Filter in WordPress admin

There is already a tutorial about custom taxonomy filter on my blog. Now it is time how to create a similar filter by authors.

Please note, that the filter is going to work for every registered post type by default unless you add a custom condition in the beginning of the function.

And here is how it is going to look like

filter posts by author in WordPress admin

All you need to do is to paste the following code to functions.php file of your current theme (not necessary that file by the way, please read more here).

add_action( 'restrict_manage_posts', 'rudr_filter_by_the_author' );

function rudr_filter_by_the_author( $post_type ) {
	
	// you can add a condition for a specific post type
	// if( 'my_type' !== $post_type ) {
	// 	return;
	// }

	$selected = isset( $_GET[ 'user' ] ) && $_GET[ 'user' ] ? $_GET[ 'user' ] : '';
 
	wp_dropdown_users(
		array(
			'role__in' => array( 
				'administrator', 
				'editor', 
				'author',
				'contributor'
			),
			'name' => 'author',
			'show_option_all' => 'All authors',
			'selected' => $selected
		)
	); 
}
Misha Rudrastyh

Misha Rudrastyh

Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.

Need some developer help? Contact me

Follow me on Twitter