Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add a meta box to WordPress edit posts and list only authors
* Plugin Name: Author Meta Box only with authors
* Plugin URI:
* Description:
* Author: Frank Bültge
* Author URI:
* License: GPLv3
add_action( 'admin_menu', 'fb_remove_author_meta_boxes' );
function fb_remove_author_meta_boxes() {
remove_meta_box('authordiv', 'post', 'normal');
add_meta_box('fb_authordiv', __('Author'), 'fb_post_author_meta_box', 'post', 'normal', 'core');
function fb_post_author_meta_box( $post ) {
global $user_ID;
// get all authors
$wp_user_search = new WP_User_Search($usersearch = '', $userspage = '', 'author');
$authors = join( ', ', $wp_user_search->get_results() );
<label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label>
wp_dropdown_users( array(
'include' => $authors,
'who' => 'authors',
'name' => 'post_author_override',
'selected' => empty($post->ID) ? $user_ID : $post->post_author,
'include_selected' => true
) );

This comment has been minimized.

Copy link

@benklocek benklocek commented Jul 3, 2015

Updated to use the newer WP_UserQuery, and allow for more flexible querying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.