So I was wondering if it’s possible to dynamically create meta boxes in the post admin. I have a lot of data but don’t want to hardcode every meta box needed in functions.php.
An example would be a custom post type for movies, I want to create different meta boxes for all the actors in the movie.
Is it possible to add meta boxes dynamically with the ability to add and delete them within the post admin?
Thanks!
I would seriously consider looking into the WPAlchemy metaboxes class. It does exactly what you are after and so much more.
http://www.farinspace.com/wpalchemy-metabox/#have_fields_and_multi
This class is so great that I am frankly shocked that there is not a lot more discussion about it. *If there is a better metabox class, I’d love to hear about it, though I am very happy with WPAlchemy.
It’s possible using a Metabox class that handles most of the coding for you.
I prefer using Jared Atchison and Bill Erickson’s Custom Metaboxes and Fields for WordPress class. It is very extensible and the easy to use and expand upon.
My fork of it allows you to also create taxonomy select and taxonomy radio custom fields.
Yes its possible, Take a look at Verve Meta Boxes plugin
This could also be done using JavaScript. Just have it dynamically create additional fields and then have them all target the same destination array. So the fields created by the JavaScript would be named something like this:
The action to create these client-side fields could just be attached to an “Add Actor” button or something along those lines.
I had your same requirements for a site I am developing now. I used successfully the following two plugins to help creating custom post type and meta boxes directly in admin area: Custom Post Type UI and Custom Field Template.
The only required code is creating a page-.php inside you theme folder and then use code similar to:
to retrieve and format as you want the information provided in metaboxes.
MetaBox control via a Dashboard UI:
Advanced Custom Fields – Excellent and easy.
Magic Fields 2 – I’ve used and am not a fan of it…
FWIW, I’ve never been a fan of creating metaboxes via a UI so I always use one of these two classes:
For WP Metabox PHP Classes:
CMB – My personal my favorite by Atchinson, Erickson, Norcross. It’s quick and easy for most needs.
WPAlchemy – I’m also a fan of WPAlchemy because it include repeating fields and repeating field groups which CMB has talked about adding someday but has yet do (I think everyone’s just been too busy to do it).