[wp-hackers] WP 3.0 and beyond: Custom post types + custom fields
Mohammad Jangda
batmoo at gmail.com
Fri Jun 18 20:59:47 UTC 2010
>
> Has any serious thought been given towards this aspect of WP? There are
> several plugins out there that attempt to tackle this in various ways. I'm
> curious as to if there's much interest in this making it into core, and if
> so, what steps have been made thus far.
>
I've been toying with the idea of a register_metadata_field function that
would allow you to register a custom field type much like you can custom
post types. I think it would be great to build out something like the
settings API where you can register settings, and setting sections, and
support standard input types (text, textarea, select, etc.) but also allow
custom rendering.
For anyone interested, I started writing out a method signature for the
function:
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 specified
, label => '' // Label for the field
, description => '' // Description of the field, displayed below the
input
, 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
validation
, server_validation_callback => '' // function name for server-side
validation
, show_in_columns => false // Add the field to the columns when viewing
all posts
, add_to_edit => false // Add the field to the Edit page
, add_to_quick_edit => false // Add the field to Quick edit
) );
It might be overkill for core (at this point, at least) but anyone want to
join forces to make this happen as a plugin?
Mo
--
Mohammad Jangda
www.digitalize.ca | @mjangda
On Fri, Jun 18, 2010 at 4:41 PM, William Maddler <news at maddler.net> wrote:
> On 06/18/2010 10:30 PM, Matt wrote:
> > Now that the custom post type functionality has been refined with 3.0,
> one
> > important next step would be to more closely integrate post types with
> > custom fields.
> >
> > There's no easy way -- using only core -- to assign certain custom fields
> to
> > a new post depending on its post type.
> >
> > For example, a new "Soccer Team" post type. You'd likely want to see
> custom
> > fields like "wins", "losses", "home_field", and "roster" (some sort of
> > relationship) show up by default when adding a new Soccer Team.
> >
> > The closest thing I could find was the "register_meta_box_cb" argument,
> > which lets you add new meta boxes -- not alter the "Custom Fields" area.
> >
> > Here's a *really* rough idea of how this functionality could work:
> >
> > $args = array(
> > 'public' => true,
> > 'publicly_queryable' => true,
> > 'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'),
> > 'custom_fields' => array(
> > 'wins' => array('label' => __('Wins'), 'widget' => 'number'),
> > 'losses' => array('label' => __('Losses'), 'widget' => 'number',
> > 'default' => 0),
> > 'home_field' => array('label' => __('Home Field'), 'widget' =>
> > 'text-single')
> > ),
> > ... etc ...
> > );
> > register_post_type('soccer_team', $args);
> >
> >
>
> Yes, I'd seriously be happy to see such a function in WP core. As of now
> I've been using custom fields but, you know, ain't that straight forward.
>
> Being able to easily define custom posts an attributes would make
> everything a LOT easier. IMHO
>
> Thx,
> William
>
> >
> > Matt
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list