Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.


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?

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
alright thanks it makes perfectly sense to me now! –  Paul_p May 26 '11 at 18:46
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
@Bainternet @Chip Bennett : Thanks ! (does it work to do a multiple answer like this?) Ok, when you talk about custom fields : where are they written... inside the add meta box? i've only seen for now the line "supports" for custom fields, are the parameters in the add meta box also called 'custom fields' ? codex.wordpress.org/Function_Reference/add_meta_box Or do you have another example? –  Paul_p May 26 '11 at 14:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.