WordPress has two plugin hooks that allow you to add extra markup (text, fields, etc.) to the end of the edit forms that post.php displays. They are “simple_edit_form” and “edit_form_advanced”. It would be best not to modify post.php directly, but rather write a plugin to do it.
As far as parsing the values of your custom fields go, you could try the approach I used in Cricket Moods. It does not require any changes to the database. It stores everything as standard post metadata.
Look in the source for my plugin and examine my cm_get_posted_moods() function:
/**
cm_get_posted_moods
Parses $_POST elements and returns an array of
the values (mood ids) used by CM. Returns FALSE
if no applicable values were submitted.
*/
function cm_get_posted_moods() {
$moods = array();
foreach($_POST as $key => $val) {
// CM input element names are prefixed by 'cm_mood_'.
if( substr($key, 0, 8) == 'cm_mood_' )
$moods[] = stripslashes( trim($val) );
}
if( !empty($moods) )
return $moods;
else
return false;
}
I prepended the “name” attribute of each field I added to post.php with “cm_mood_”. You can use something different. This function returns an array of the custom values, but does not use the “name” attributes for keys.
The function above is used by a function that is called by the “save_post” and “edit_post” actions. This second function basically does this:
foreach($moods as $mood_id) {
$wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_ID','mood','". $wpdb->escape($mood_id) ."')");
}
The second function is called “cm_update_moods” if you’re looking in the source.
Basically, writing a plugin would be much more effective in your situation. Feel free to use large portions of my plugin, if you need to; it has a very non-restrictive license.