Support » Plugins » Adding field to post.php

  • 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)
  • 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.

    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.

    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.

    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?

    Just curious, how come using the built in custom field with a key of Source won’t work for you?

    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.

    You could use the meta data to do this. Here’s how you can insert meta data for each post.

    Then you can use the function get_post_meta() to extract the data while inside TheLoop. The function is undocumented so far, but it’s pretty straigh forward, pop open wp-includes/functions.php and goto line #475.

    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.

    any luck with this msky?

    Msk (and anyone else), I wrote a tutorial on adding custom inputs, located at, 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.

    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:


    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;
    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.