get_results( "SELECT * FROM $wpdb->users users INNER JOIN $wpdb->usermeta usermeta ON usermeta.user_id = users.ID AND usermeta.meta_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "user_level' AND usermeta.meta_value != 0 WHERE ( users.user_login LIKE '%$search_term%' OR users.display_name LIKE '%$search_term%' OR users.user_email LIKE '%$search_term%' ) ORDER BY users.display_name" ) ) && is_array( $authors ) ) { // build search results $results = array(); foreach ( $authors as $author ) { $results[] = array( 'user_id' => $author->ID, 'user_login' => $author->user_login, 'display_name' => $author->display_name, 'email' => $author->user_email, 'value' => $author->ID, 'label' => $author->display_name, ); } // "return" results echo json_encode( $results ); } } die(); } /* * Gets gravatar for selected user. */ add_action( 'wp_ajax_authors_autocomplete_mb_get_user_gravatar', 'ajax_authors_autocomplete_mb_get_user_gravatar' ); function ajax_authors_autocomplete_mb_get_user_gravatar() { if ( $user_id = ( isset( $_POST[ 'authors_autocomplete_mb_user_id' ] ) && !empty( $_POST[ 'authors_autocomplete_mb_user_id' ] ) ) ? $_POST[ 'authors_autocomplete_mb_user_id' ] : NULL ) { $gravatar_size = ( isset( $_POST[ 'authors_autocomplete_mb_gravatar_size' ] ) && !empty( $_POST[ 'authors_autocomplete_mb_gravatar_size' ] ) && $_POST[ 'authors_autocomplete_mb_gravatar_size' ] > 0 ) ? $_POST[ 'authors_autocomplete_mb_gravatar_size' ] : 32; // "return" gravatar echo get_avatar( $user_id, $gravatar_size ); } die(); } /* * Figures out if what the user entered is an actual user. * If user exists, returns user info. */ add_action( 'wp_ajax_authors_autocomplete_mb_if_user_exists_by_value', 'ajax_authors_autocomplete_mb_if_user_exists_by_value' ); function ajax_authors_autocomplete_mb_if_user_exists_by_value() { global $wpdb; if ( $user_value = ( isset( $_POST[ 'authors_autocomplete_mb_user_value' ] ) && !empty( $_POST[ 'authors_autocomplete_mb_user_value' ] ) ) ? $_POST[ 'authors_autocomplete_mb_user_value' ] : NULL ) { if ( $author = $wpdb->get_row( "SELECT DISTINCT * FROM $wpdb->users users WHERE ( users.user_login LIKE '$user_value' OR users.display_name LIKE '$user_value' OR users.user_email LIKE '$user_value' )" ) ) echo json_encode( $author ); echo false; die(); } } /* * Remove the core "author" meta box and add our * custom "author" meta box. */ add_action( 'add_meta_boxes', 'authors_autocomplete_mb_add_meta_boxes', 1, 2 ); function authors_autocomplete_mb_add_meta_boxes( $post_type, $post ) { global $wp_meta_boxes; if ( ( $screen = get_current_screen() ) && ( $post_type == $screen->id ) && post_type_supports( $post_type, 'author' ) && ( $post_type_object = get_post_type_object( $post_type ) ) && ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) ) { /* * We can't simply remove_meta_box() because WordPress * doesn't like us removing/replacing core WordPress * meta boxes. If you use remove_meta_box( 'authordiv' ), it * sets the box in $wp_meta_boxes as "false" which blocks us * from using add_meta_box( 'authordiv' ). */ foreach( $wp_meta_boxes as $mb_post_type => $mb_post_type_context ) { foreach( $mb_post_type_context as $context => $mb_post_type_priority ) { foreach( $mb_post_type_priority as $priority => $mb_post_type_meta_boxes ) { foreach( $mb_post_type_meta_boxes as $mb_id => $mb ) { if ( 'authordiv' == $mb_id ) unset( $wp_meta_boxes[ $mb_post_type ][ $context ][ $priority ][ $mb_id ] ); } } } } /* * Time to add our own author meta box. */ add_meta_box( 'authors_autocomplete_mb_authordiv', __( 'Author' ), 'authors_autocomplete_mb_post_author_meta_box', $post_type, 'normal', 'core' ); } } /* * Print our custom "author" meta box. */ function authors_autocomplete_mb_post_author_meta_box( $post, $metabox ) { global $user_ID; if ( ( $post_type = ( isset( $post->post_type ) && ! empty( $post->post_type ) ) ? $post->post_type : NULL ) && post_type_supports( $post_type, 'author' ) && ( $post_type_object = get_post_type_object( $post_type ) ) && ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) ) { // get selected author $author = isset( $post->post_author ) ? get_user_by( 'id', $post->post_author ) : get_user_by( 'id', $user_ID ); ?>
'authors', 'name' => 'post_author_override', 'selected' => ( isset( $author ) && isset( $author->ID ) ) ? $author->ID : $user_ID, 'include_selected' => true )); ?>
ID, 32 ); ?>

You can search for the author by display name, login, or e-mail address.