Title: Adding field to post.php
Last modified: August 18, 2016

---

# Adding field to post.php

 *  [msky](https://wordpress.org/support/users/msky/)
 * (@msky)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/)
 * I need to expand the admin posting page to include a custom field, with its own
   unique form fieldset, rather than using the custom fieldset. I’ve added a custom
   field (“source”), and have added the fieldset to edit-form-advanced.php. And 
   I have index.php set up to display the input.
 * But there’s something I have to add to post.php to make things work. I’m new 
   to php so thanks for any help with this.
 * Name of the custom field is “source”

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [carthik](https://wordpress.org/support/users/carthik/)
 * (@carthik)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162263)
 * Since you are not too experienced with php / javascript I would suggest that 
   this might be too difficult to attain. Untein’s livepress is the only plugin 
   I know of that adds custom fields in the advanced posting UI using javascript,
   and that was an elaborate little hack.
 *  Thread Starter [msky](https://wordpress.org/support/users/msky/)
 * (@msky)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162364)
 * Thanks for the advice. What I did manage to do was to alter the edit page so 
   that the custom fields section comes right after the title, which is more convenient
   and logical for my for my posting. And I deleted the Excerpt section which I 
   don’t use. And along the way I got a little more comfortable with php.
 *  [chuyskywalker](https://wordpress.org/support/users/chuyskywalker/)
 * (@chuyskywalker)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162457)
 * You deleted the excerpt form? You better keep really good tabs on what you have
   and haven’t modified because when it comes time to update you’re going to be 
   in for a doozy if you’ve modified a lot of the core WP files.
 *  Thread Starter [msky](https://wordpress.org/support/users/msky/)
 * (@msky)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162476)
 * I copied and renamed post.php and then made my changes. But I’m already unhappy
   with the result, still not doing what I need, so I’m switching back.
 * If you add fields to your mysql database, is there no way to place those fields
   for input on the edit and post pages?
 *  [oriecat](https://wordpress.org/support/users/oriecat/)
 * (@oriecat)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162477)
 * Just curious, how come using the built in custom field with a key of Source won’t
   work for you?
 *  Thread Starter [msky](https://wordpress.org/support/users/msky/)
 * (@msky)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162483)
 * I’m building a site for a client that will require four or five extra/custom 
   fields. Though they could use the current set up to choose a key, input value,
   save, repeat, repeat, repeat, it would be much better if, like a database program,
   they could just have a page that tabbed from field to field then save.
 * I get that this is nudging WordPress from blog software to Content Management
   System. Seems like something WP should be able to do, but I’m still too php-dumb
   to figure out.
 *  [chuyskywalker](https://wordpress.org/support/users/chuyskywalker/)
 * (@chuyskywalker)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162502)
 * You could use the meta data to do this. [Here’s how you can insert meta data for each post.](http://codex.wordpress.org/Using_Custom_Fields)
 * Then you can use the function get_post_meta() to extract the data while inside
   [TheLoop](http://codex.wordpress.org/The_Loop). The function is undocumented 
   so far, but it’s pretty straigh forward, pop open `wp-includes/functions.php`
   and goto line #475.
 *  Thread Starter [msky](https://wordpress.org/support/users/msky/)
 * (@msky)
 * [21 years, 2 months ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162526)
 * Unless I’m missing something, this just takes me to where I was above. I can 
   add new custom fields/keys and get the values to show up where I want in the 
   posts. What I can’t figure out is how to change “edit-form-advanced.php” or “
   edit-pages.php” so that the new fields show up as unique input fieldsets. (sorry
   if my syntax sucks).
 * So, when the user goes to new page, they see a new form that has my new fields
   ready to take new data.
 *  [amory](https://wordpress.org/support/users/amory/)
 * (@amory)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162721)
 * any luck with this msky?
 *  [amory](https://wordpress.org/support/users/amory/)
 * (@amory)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162730)
 * Msk (and anyone else), I wrote a tutorial on adding custom inputs, located at
   [http://www.bluewebpages.com/blog/2005/05/customfields](http://www.bluewebpages.com/blog/2005/05/customfields),
   if interested. It is a bit more in-depth than having the existing custom fields
   remain fixed, but I was unable to accomplish the later task.
 *  [kccricket](https://wordpress.org/support/users/kccricket/)
 * (@kccricket)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162731)
 * WordPress has two [plugin hooks](http://codex.wordpress.org/Plugin_API) 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](http://dev.wp-plugins.org/file/cricket-moods/tags/1.0.1/cricket-moods.php).
   It does not require any changes to the database. It stores everything as standard
   post metadata.
 * Look in the [source](http://dev.wp-plugins.org/file/cricket-moods/tags/1.0.1/cricket-moods.php)
   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.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Adding field to post.php’ is closed to new replies.

 * 11 replies
 * 6 participants
 * Last reply from: [kccricket](https://wordpress.org/support/users/kccricket/)
 * Last activity: [21 years, 1 month ago](https://wordpress.org/support/topic/adding-field-to-postphp/#post-162731)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
