51 responses to “Take Your WordPress Meta Box to the Next Level”

  1. terry

    This is great!!! Thank you!

    Does this work on 3.0? I just tried this and the fields don’t show up in the meta boxes

  2. Horia

    Dimas, first of all, thanks for your tutorials about wp metaboxes.

    I have started using your class and any future updates are more than welcome.

  3. Terry

    The Meta Box block “My Custom Custom Meta” is there but none of the fields show up?

    There must be something I’m missing…

    I’ll guess i’ll give this a try when they release 3.0 and see if I have some luck

  4. donalyza

    Hi. I was able to make this to work on a regular post. Apparently when I use it on a custom post_type, in admin panel everything seems fine. I can see the custom fields but not showing when pulled-up on the site. I use the same code in my theme template.

  5. Tom

    Hi again Dimas – I love that you’re continuously improving upon this code! Awesome : )

    Although there is an issue – this code can’t be used if your host is running PHP4. I know everyone SHOULD be using PHP5, but for those clients out there who don’t know any better, is there a way to make this compatible with both versions of PHP?

    And just for the record, here’s the error:

    PHP Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’

    Thanks a lot man, and keep up the awesome work.

  6. Tom


    I was foolish last night and upgraded my PHP version – I actually had no idea I was running PHP4 until I tried to implement this – so I can’t even test the fix : (

    Does the fix recognize the PHP version and output the necessary code?

  7. Tom

    Dimas – I see now : )

    Is there a way to make it more user friendly so if it’s implemented in a theme that someone has, and they have no idea how to deal with all the code, that it’s just done for them?

    I’m thinking like a “if php4 display: this, else, display: this” type of thing?

  8. Tom

    Something like this –

    if (version_compare(PHP_VERSION, ‘5.0.0’, ‘<')) {
    include_once 'meta.php4';
    } else {
    include_once 'meta.php'; }

    I wish I didn't upgrade my php version, now I can't test to see if it works! lol

  9. Dimas

    Check out: http://farinspace.com/2009/06/running-php4-and-php5-in-parallel-the-easy-way/ … you might be able to run both PHP4 and PHP5

  10. Dimas

    Tom, I’ll probably just use the PHP4 version as the main release … WordPress currently is still compatible with PHP4, so there will definitely be users using PHP4, plus considering developers will be using this code to create plugins/themes, making it PHP4 compatible will allow developers to use it in a wider range of projects.

  11. Tom

    Thanks for the link about running both – the whole server side of websites is an area I need to study more.

    Sounds good to me – I’m not much a PHP guy yet, but noticed the main difference was that the php5 version had “protected” and “private”, while the php4 version is using “var”.

    What are the advantages to the php5 way?

  12. Tom

    Back again – I know.

    So I’ve been dissecting and really enjoying your code – especially the loops where it adds fields for you on save. Is there an easy to way to implement jquery to add more fields on the click of a link, instead of having to save each time?


  13. Tom

    Also, is there anywhere I can buy you a coffee/beer?

  14. Tom

    Can’t wait! Very interested in seeing how it works : )

  15. Luke


    Once again you are the man! AWESOME code, works like a charm.

    I second the coffee/beer idea from Tom.

  16. dandy

    This is very nice indeed. I was just stepping into add_meta_box() functions and found this lib.
    Good code.

  17. Tom

    Very interesting! Thanks, Dimas!

  18. Russell Parrott

    Hi Dimas
    This is a great PHP class – and yes it does work well with WP3.0 as you say/state. I only have one question/problem.
    In one of my meta boxes I need to use a custom WP loop query to create a dropdown of WP post titles belonging to a specific custom-post type.

    When ever I add/update a post with this dropdown the class always adds an additional “option” field to the output. e.g.:


    which should acually be


    In other words it always adds/appends the first select option of the custom query at the end of the update. Any ides/suggestions please. fyi here is “my code”

    get_results($querystr, OBJECT); ?>
    <?php foreach ($pageposts as $post): 		
    $postoptions .='ID.'">'.$post->post_title.'';
    endforeach; ?>		
    have_fields_and_multi('docs')): ?>
    the_group_open(); ?>
    the_field('products'); ?>
    <select name="the_name(); ?>">
    the_field('productqty'); ?>
    <input type="text" name="the_name(); ?>" value="the_value(); ?>"  />
    <a href="#" rel="nofollow">Remove Document</a>
    the_group_close(); ?>	
    <a href="#" rel="nofollow">Add Options</a> - <a href="#" rel="nofollow">Remove All</a>
  19. Joel

    Fantastic class. Thank you so much for sharing this. My one suggestion would address the issue I have been struggling with this morning. I think adding in a method to use the existing media library to insert image URL’s directly into a MetaBox field would be incredibly useful. For me, the beauty of using the custom MetaBox is reducing the number of steps a user needs to take in order to generate pre-formatted content.

    I am presently building a MetaBox to add a product to a page. This requires a couple of fields, including on that takes an image url. A simple way to launch the media uploader/library to select an image and insert into this field would be brilliant.

    If you have any suggestions on how I could do this in the meantime it would be greatly appreciated. Thanks again!

  20. Ashfame


    That’s really a useful contribution. Does it work on WP 3.0 fully? I read comments that there were some issues.

    Did you roll out the updates for WP 3.0?

    And also please turn on the dates of comment to show up, it makes life easy to read when the comment was actually written.


  21. samuel arendt

    Já estou testando seu trabalho, eu estou construindo um tema padrão e criando bibliotecas para re-uso nos projetos, e seu trabalho irá somar muito :)

    Uma consideração, em vez de usar:
    $_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/twentyten/custom/meta.php'
    ficaria mais fácil para re-uso, assim:

    STYLESHEETPATH. '/custom/meta.php'

  22. Ashfame

    I just wrote a comment above this one asking you something and you ignored it.

  23. Ashfame

    Great! I will let you know how well it goes.

  24. diogoosorio

    Just wanted to leave a big THANKS from Portugal. Ive used the class and it saved me a ton of time! It worked flawlessly for me, once again thanks a lot!

  25. David Alexander

    When I downloaded the latest version of wp alchemy there wasnt a meta.php but a meta2.php which was only 8 bites large and contained the word CONTENT. Is this something new? Trying to get this to take with wp3 and thesis.

  26. David Alexander

    Just to update I am following through http://farinspace.com/multiple-wordpress-wysiwyg-visual-editors/ and the meta box appears but isnt editable and has CONTENT printed inside it. But no wysiwyg. Any ideas where I am going wrong?

  27. David Alexander

    Hi Dimas,

    Thanks for that, I got it working, though having a couple of issues with displaying the results of both meta and meta2, for now I am using multiple fields within one meta, that will still allow me the flexibility to show these fields individually I presume.

    I have been going through the docs etc and its starting to make more sense as I refer to that then comment discussions. My idea for using this is to allow a 1, 2 and 3 column template in wp/thesis and use these new fields as sidebar 1 sidebar 2 and sidebar 3 to let the user control their sidebar content sitewide and on all pages, posts etc using the default the sidebar will fall back on the widgets page sidebar content. Wish me luck :) and keep up the good work, will let you know how I get on with the template side of things. Im considering seeing if I can create a widget that calls your chosen meta field, and then register some new sidebars and have a widget pull this meta info. Any thoughts?

    Have a good weekend.

  28. David

    Thanks for your suggestion. I would personally try that, but I feel for the client they will want to just use pages to help them understand the process better.

    What I did have in mind was to have the 3 additional meta boxes available and have page templates selectable from the edit page screen sidebar that would list

    Default (show default sidebar 1 accessed on widgets page)
    1 Custom Sidebar (Show the meta content of extracontent1 in a new sidebar)
    2 Custom Sidebars (Show the meta from extracontent2 and 3)

    What I was going to do then was create some new widgetized areas and call them custom sidebar 1, custom sidebar 2, and custom sidebar 3, adding widgets or shortcodes to each so they display the content of the above.

    I really want to explore more with custom post types and have another project where I am using them but still finding a few things a little fiddly. Any thoughts on the media buttons and your preferred approach Dimas? :) Hope your well. Love the script, this has so much potential to open wordpress up.

  29. Vadim

    Hey how do I actually display the custom meta boxes in the posts?

  30. Kevin

    Can this class be used with Thesis theme?

  31. David

    I use it with Thesis Kevin. FYI.

  32. amin

    Hi,How to limit meta box display rely on post format?By the way i’v used the way you had mentioned for custom template but it didn’t work .

  33. Shir Gans


    I think something is missing. I’ve tried to make things work but the data just not saved.
    wpalchemy is in wp-content.
    I got the custom folder set with meta.php and meta.css.
    I got the metaboxes folder with all files.
    Here’s my code (functions.php):

    include_once 'metaboxes/setup.php';
    include_once 'metaboxes/simple-spec.php';
    include_once 'metaboxes/full-spec.php';
    include_once 'metaboxes/checkbox-spec.php';
    include_once 'metaboxes/radio-spec.php';
    include_once 'metaboxes/select-spec.php';

    $custom_metabox = new WPAlchemy_MetaBox(array
    'id' => '_custom_meta', // underscore prefix hides fields from the custom fields area
    'title' => 'My Custom Meta',
    'template' => TEMPLATEPATH . '/custom/meta.php'

    so the meta box appears perferctly but the data is not saved.
    I tried it all over again, but it didn’t help.
    Any idea ?

  34. Shir Gans

    Ignore the above.
    I found what went wrong.
    I had to use the metaboxes folder in order to create a new metabox.

    Cheers ! wonderful class

  35. Marco Berrocal

    Okay this may be the dumbest question on earth but I’d rather be dumb for 5 minutes than for an eternity, but wtf is a meta box?

    Sorry for the dumb question but I am kind of in need for some custom variables and mixture of excerpts so that my client can manipulate the jQuery, etc.

  36. Brandon

    Hi everyone. I purchased a theme from Themforest.

    Can you… or do you know of anyone that could add a “Create a new Sidebar for this page?” in the “Product Metaboxes” section? Exactly what you typically have in the “Pages Metaboxes”. I will obviously pay as i know this is completely custom work. I can pay with PayPal.

    Thank you kindly my friend!

  37. Victor Haglund

    Hello again!
    Just wanted to give you props again for this superb solution to meta boxes, and again thank you so much for making this available for the community!!

    If you ever happen to be in Sweden, I will buy you all the beer you can drink and show you around town!

    Best regards Victor

  38. Fliberty

    Hello as they are, I wonder if it is possible to show metaboxes blocks in a form of publication created to run from the front-end and not the administration, meaning that in this form can be shown my mteabox where the user can select or mark the different options.

Leave a Reply