add meta box – custom field : which to choose?

i’ve just find out about the custom field, which makes it possible to add something near a post, but what is the difference between “add_meta_box” and “custom field”?

Custom field is inside the “supports” line, when we register a post type, so : isn’t it easier to create a custom field than a add meta box? or are there many differences between both?

Related posts

Leave a Reply

4 comments

  1. A meta box is an element in the graphical user interface, a custom field is an extra key and value stored with a post. Most of the time the interface to change the value of a custom field is put in an extra meta box – or in the default meta box for custom fields, which you can enable per post type.

    Maybe a picture can help explain this. I have a post with two custom fields: my_custom_field and _thumbnail_id. In the database they are stored in the wp_postmeta table:

    Database rows showing custom field data

    But in the post interface they can be edited in different places. The _thumbnail_id is displayed in the Featured Image meta box and can be edited with the image browser because it is hard to know the attachment ID. The other value can just be edited via the “generic” Custom Fields meta box:

    Custom Fields and Featured Image meta boxes

    It will depend on the values you need to enter in your plugin and the experience of your users whether the Custom Fields meta box is enough, otherwise it will be more user-friendly to add a separate meta box.

  2. Custom filed is a post meta field
    meta box is used to group a section in the new/edit post/page screen which are by default:

    • Comments status metabox.
    • Comments metabox.
    • Slug metabox.
    • Revisions metabox.
    • Author metabox.
    • Custom fields metabox.
    • Excerpt metabox.
    • Trackbacks metabox.
    • Featured image metabox.
    • Formats metabox.
    • Tags metabox.
    • Categories metabox.

    Now a custom metabox usually is a grouping of custom fields for example when using an SEO plugin you see a new metabox with fields like title, description, keywords…(most of them anyway), and that is exactly a custom metabox which uses custom fields (post meta) to store the data the user inputs.

    so usually there is no difference between the fields and its easier to just add a custom fields but its not very user friendly as a custom metabox.

  3. They are just different things:
    1) add_meta_box -> it just help you to add an interface, a meta box as the function name which help you to display forms, inputs, different data
    2) custom field -> this is a custom value assigned to a given post type.

    You should just use booth, use the add_meta_box to add the interface and hold all submitted information into the custom fields

  4. Both merely add custom post metadata. Which to use depends on the use case. If you are developing something for end users, I would recommend using the Metabox, as generally speaking, the metabox UI is more user-friendly than the custom field UI.