How To Enhanced Author Filtering In The Admin Posts Table

Last Updated on November 11, 2023 by Mike Kipruto

In this post, we will explore the process of enhancing the filtering functionality of the posts table in the WordPress admin panel by adding a new filter based on the author.

The issue at hand revolves around managing a website with multiple authors, where the absence of a specific author filter makes it challenging to sort posts.

To address this problem effectively, we will introduce a code snippet that incorporates a dropdown list filter for authors directly into the posts table within the WordPress admin panel.

This new filter will seamlessly complement the existing date and category dropdown lists as shown:

Enhance author filtering by Mike Kipruto
PHP
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' => 'All authors',
			'selected'        => get_query_var( 'author', 0 ),
			'name'            => 'author',
			'who'             => 'authors',
			// 'role__in'        => ['author','editor','administrator'],
		] );
	}
}

In the provided code snippet, we have hooked into the restrict_manage_posts action hook, which is triggered prior to the “Filter” button on the Posts and Pages list tables.