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

    Dimas,

    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?

    Thanks!

  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

    Dimas,

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

    a:1:{s:4:"docs";a:3:{i:0;a:2:{s:8:"products";s:3:"131";s:10:"productqty";s:3:"342";}i:1;a:2:{s:8:"products";s:3:"140";s:10:"productqty";s:4:"3254";}i:2;a:1:{s:8:"products";s:3:"131";}}}
    

    which should acually be

    a:1:{s:4:"docs";a:3:{i:0;a:2:{s:8:"products";s:3:"131";s:10:"productqty";s:3:"342";}}}
    

    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>
    
1 2 3

Leave a Reply