Dynamically Creating Meta Boxes

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.

Read More

Is it possible to add meta boxes dynamically with the ability to add and delete them within the post admin?

Thanks!

Related posts

Leave a Reply

6 comments

  1. It’s possible using a Metabox class that handles most of the coding for you.

    *If there is a better metabox class, I’d love to hear about it, though I am
    very happy with WPAlchemy.

    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.

  2. Yes its possible, Take a look at Verve Meta Boxes plugin

    Once installed, you will find a
    configuration screen located under
    Tools in the left navigation. There
    you can create multiple meta boxes
    each with a set of user defined drag
    and drop sortable custom fields. See
    the screenshots for more detail.

  3. 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:

    <input type="text" name="actors[actor1]" id="actors[actor1]" />
    <input type="text" name="actors[actor2]" id="actors[actor2]" />
    <input type="text" name="actors[actor3]" id="actors[actor3]" />
    

    The action to create these client-side fields could just be attached to an “Add Actor” button or something along those lines.

  4. 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:

    <h1><?php echo get_post_meta($post->ID, 'Name', true); ?> "<?php echo get_post_meta($post->ID, 'Title', true); ?>"</h1>
    

    to retrieve and format as you want the information provided in metaboxes.

  5. 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).