• Resolved charismabiz

    (@charismabiz)


    How would I add a field in the Write/Manage posts page to add a custom column?

    I can add it in manually by editing post-new.php and post.php, but was wondering if there’s a way to do it via plugins.

    Mainly involving the code. Database-wise, it’s easy to add a new column to wp_posts table.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    a) You should not be adding new columns to the posts table. You should use custom fields instead, using the *_post_meta() functions. Or you should create your own table. Modifying core table is just as bad as modifying core code: it makes it impossible to upgrade easily for that blog later.

    b) There are action hooks all over the editing code for you to hook into. simple_edit_form, edit_form_advanced, edit_page_form. You’ll also need to use hooks to receive and save the incoming form data: publish_post, edit_post, save_post, wp_insert_post, delete_post, etc.

    Thread Starter charismabiz

    (@charismabiz)

    Thanks for the first part, new table it is.

    As for the second part, I’ll look into it. Are the editing hooks the same as for post creation, or are they just for editing?

    And can you tell me (or link me to) more information regarding post_meta?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    There’s not a lot of good documentation on those, though the functions are fairly obvious and easy to use.

    Look for these functions in the source code:
    add_post_meta
    delete_post_meta
    get_post_meta
    update_post_meta

    And examine them. They are fairly obvious. Basically you can add key->value pairs to any post and be able to pull it back later.

    As for the editing hooks, I’m not entirely certain. You may just want to search through the source and find them to see where they are and what they do.

    The best documentation on WordPress is WordPress itself. Whenever I want to know, I just go read the source code.

    Thread Starter charismabiz

    (@charismabiz)

    I just found a section on the post create/edit pages where you can add custom fields

    May still need those hooks to make the section more informative (eg: specifying a required specific field).

    d9r

    (@d9r)

    a) You should not be adding new columns to the posts table. You should use custom fields instead, using the *_post_meta() functions. Or you should create your own table. Modifying core table is just as bad as modifying core code: it makes it impossible to upgrade easily for that blog later.

    b) There are action hooks all over the editing code for you to hook into. simple_edit_form, edit_form_advanced, edit_page_form. You’ll also need to use hooks to receive and save the incoming form data: publish_post, edit_post, save_post, wp_insert_post, delete_post, etc.

    It would help if the documentation explained this better.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding new field to write/edit’ is closed to new replies.