Here it is. Thanks Lester.
Thank you Lester! (the answer to my previous post)
<?php
/*
Plugin Name: WP-Add Author Custom Fields
Plugin URI: https://www.lesterchan.net/portfolio/programming.php
Description: Adds default author fields to make author name and username meta-data that can be searched with Kaf's search custom fields plugin (https://guff.szub.net/2006/04/21/search-custom-fields/).
Version: 1.11
Author: Lester 'GaMerZ' Chan
Author URI: https://www.lesterchan.net
*/
/*
Copyright 2007 Lester Chan (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
### Function: Add Author Custom Fields
add_action('publish_post', 'add_author_fields');
function add_author_fields($post_ID) {
global $wpdb;
$user_id = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_ID");
$first_name = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'first_name' AND user_id = $user_id");
$last_name = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'last_name' AND user_id = $user_id");
$user_name = $wpdb->get_var("SELECT user_login FROM $wpdb->users WHERE ID = $user_id");
add_post_meta($post_ID, 'author_realname', $first_name.' '.$last_name, true);
add_post_meta($post_ID, 'author_username', $user_name, true);
}
?>