2

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!

1
  • Any progress on that question?
    – kaiser
    Commented Jan 30, 2014 at 11:46

6 Answers 6

3

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.

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.

1
0

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
  • Thanks Bainternet, I actually tried that plugin as a solution but it doesn't work for what I'm looking for. I appreciate the help!
    – Marco
    Commented Apr 14, 2011 at 14:40
  • Another plugin that enables something similar is Magic Fields. You could have a look at how they use JS to duplicate Meta Fields.
    – Milo
    Commented May 13, 2011 at 21:42
  • The problem with link-only answers: Link rot. The plugin is gone...
    – kaiser
    Commented Jan 30, 2014 at 11:47
0

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.

2
0

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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