Discuss your project
Wordpress Backoffice

WordPress: Add a filter by author in the admin posts list

To add an author filter on the list of articles page available in WordPress, simply add the following code to the functions.php file: Note: I have left the comment on the conditional instruction concerning the post types, it might come in handy 😊 function r...

WordPress: Add a filter by author in the admin posts list

To add an author filter on the list of articles page available in WordPress, simply add the following code to the functions.php file:
Note: I have left the comment on the conditional instruction concerning the post types, it might come in handy 😊

function restrict_manage_authors() {
/*if (isset($_GET['post_type']) && post_type_exists($_GET['post_type']) && in_array(strtolower($_GET['post_type']), array('your_custom_post_types', 'here'))) {
*/wp_dropdown_users(array(
'show_option_all'	=> 'Show all Authors',
'show_option_none'	=> false,
'name'			=> 'author',
'selected'		=> !empty($_GET['author']) ? $_GET['author'] : 0,
'include_selected'	=> false
));
/*}*/
}
add_action('restrict_manage_posts', 'restrict_manage_authors');

Reproduce this customization today

The principle of the hook remains useful, but the administration screens and WordPress APIs have evolved since the publication. Test the code in a staging environment with the exact version of the site's core, theme, and plugins.

  • Save the files and the database before making any changes.
  • Control user capabilities, nonces, input validation, and output escaping.
  • Place customizations in a dedicated plugin or a child theme to preserve updates.

Reference: official WordPress plugin development manual.

Share this article