Filter posts by author in WordPress admin area

Maybe you have already read the post about custom taxonomy filter on my blog. And now I will show you how to create the same filter by the authors. The filter will work not only for posts but also for pages and custom post types. Here it is: This code is for your current theme […]

#wp-admin  /    /   28

Maybe you have already read the post about custom taxonomy filter on my blog. And now I will show you how to create the same filter by the authors.

The filter will work not only for posts but also for pages and custom post types.

Here it is:

How to filter all posts by authors in WP administration area.

This code is for your current theme functions.php file:

function rudr_filter_by_the_author() {
	$params = array(
		'name' => 'author', // this is the "name" attribute for filter <select>
		'show_option_all' => 'All authors' // label for all authors (display posts without filter)
	);
 
	if ( isset($_GET['user']) )
		$params['selected'] = $_GET['user']; // choose selected user by $_GET variable
 
	wp_dropdown_users( $params ); // print the ready author list
}
 
add_action('restrict_manage_posts', 'rudr_filter_by_the_author');
Misha Rudrastyh
About the author Misha Rudrastyh

Passionate about WordPress and snowboarding, creating websites for over 10 years! Let's work together — just contact me.

If you are a developer too, subscribe to my facebook page.

Comments 28

← Older
  • Great post, easy to implement! Any idea if it’s possible to do the same to user groups created using User Groups (https://wordpress.org/plugins/user-groups/) ?

    • Hi Joana,

      Hmmm… try to play with restrict_manage_posts hook priority, set it to 1 and if it doesn’t help – to 9999.

  • Cool!
    Is there a way to get first_name and last_name in the dropdown menu?

    • Hi Ivan,

      $params = array(
      	'name' => 'author',
      	'show_option_all' => 'All authors',
      	'show' => 'display_name' // or you can use 'ID' or 'user_login'
      );
  • Fantastic basic and clear way!

    Add extra section for this code use this link.

    https://codex.wordpress.org/Function_Reference/wp_dropdown_users

  • Is there a way to limit the filter menu to include only privileged users?

    • Yes, you can use role (accepts string), role__in (accepts array) or role__not_in (accepts array) params of wp_dropdown_users() function.

      Example:

      $params = array(
      	'name' => 'author',
      	'show_option_all' => 'All admins',
      	'role' => 'administrator'
      );
  • Thanks, perfect :)

  • AWESOME

  • This is perfect code, only one issue that i am facing. It shows a list of authors but with – author selected by default. The selected author is the author of post that appears on top of the page. Is there a way to not to select author in the filter by default?

Comments are closed.
If you need my personal help, please contact me. Contact me