[wp-hackers] WP 3.0 and beyond: Custom post types + custom fields
jer at simianuprising.com
Fri Jun 18 22:09:03 UTC 2010
On Fri, Jun 18, 2010 at 4:59 PM, Mohammad Jangda <batmoo at gmail.com> wrote:
> It might be overkill for core (at this point, at least) but anyone want to
> join forces to make this happen as a plugin?
The general idea is definitely appropriate for core. It's an obvious and
common need, and when putting together a theme the functions.php file is an
obvious place to define custom fields that will be displayed in the theme.
I actually have something like this hacked together for myself that lets me
define an array in functions.php which then gets converted into a metabox
(hacked it off an old coffee2code plugin that no longer works). It is
incredibly useful and handy and I couldn't live without it. Having the same
functionality in core is a no-brainer.
Your proposed function is pretty intense, though most of it seems relevant.
Ideally it would be modeled on the Settings API and add_settings_field() but
those functions are a huge mess and dearly in need of some wp_parse_args(),
so I like your idea of balancing the mandatory info and overrides.
Not sure about the naming, here are some other ideas:
They get pretty long at the end there but I think its worth being specific.
"metadata" is a very general term in WP especially with the 'metadata api'
that can be used for any purpose. Specifying 'post' (as in 'post-type', not
as in post-type='post') will make it much clearer.
We'd probably also want something like:
Which could be used to define a 'group' which would have its own metabox,
similar to add_settings_section().
The paste and formatting of your proposed function were all messed up in my
gmail so I'll repaste it below (also at http://pastie.org/1010807 ):
register_metadata_field('fieldName1', 'post-type', array(
'group' => '', // To which meta_box the field should be added
'field_type' => 'text', // The type of field; possibly values:
text,checkbox, radio, select, image. 'custom' if display_callback is
'label' => '', // Label for the field
'description' => '', // Description of the field, displayed below the
'value' => array(), // values for select, checkbox, radio buttons
'display_callback' => '', // function to render the field, if not using
a built-in type
'save_callback' => '', // function name for saving
'client_validation_callback' => '', // function name for client-side
'server_validation_callback' => '', // function name for server-side
'show_in_columns' => false, // Add the field to the columns when viewing
'add_to_edit' => false, // Add the field to the Edit page
'add_to_quick_edit' => false // Add the field to Quick edit
Code and Design | globalvoicesonline.org
More information about the wp-hackers