39 responses to “How to Limit the Display of a WordPress Meta Box”

  1. Meditation Ebooks

    Wow, this is pretty cool. Thanks for sharing with us. This will certainly help me in my WordPress projects

  2. Pete

    This is nearly exactly what I’m looking for. Except rather than having a custom field meta box, I only want a blank meta box with a title and some text, much like a simple information meta box that I can rag and drop around the page edit control panel.

    If I ask really, really nicely would you be able to show me how that would be coded for a specific page.

    Thanks heaps. Cheers, Pete

  3. Pete

    Thanks for that… I’ll digest it and see how I go… thanks again :)

  4. Cosmin


    Considering WP 3.0 will have custom post types, would the following code make a meta box appear only under a defined post type?

    Let’s say I have a custom post type named “realestate”.

    Would the following make my custom meta box appear only under Real Estate (and not in Posts):

    if ($_POST['post_type'] == ‘realestate’)


    Thanks in advance :)

  5. Ross

    Exactly what I was looking for today. Even posted on the WP forums but have hence added your solution there.


    (And hey, what’s up with the nifty addthis widget? How do you get it to start sticking after scrolling past the header?)

  6. Ross

    How about adding a meta box specific to a group of pages under a page parent. I’m struggling with adding the following conditional into your function. I thought declaring global $post would do it but it won’t show.

    global $post;
    if (is_page() && $post->post_parent == '3488')
    	add_meta_box('my_meta', 'My Custom Meta Box', 'my_meta_setup', 'page', 'normal', 'high');
  7. Ross

    Works! Thanks for the quick reply Dimas.

    WPAlchemy class looks dope. Depending how many of these darn meta boxes I need will most likely be useful. Is there a plugin on the roadmap?

  8. Justin Bartlett

    If I’m using the WPAlchemy_MetaBox class for creating my meta boxes, what code would I place in functions.php to have the meta boxes only display on a custom post type e.g. events?

    And I guess for calling the values I’d just follow “using the meta box values in your template” for the custom template I set up for events?

  9. Justin Bartlett

    You sir are the man. You are the man. Who’s the man? Your the man.

    Thanks so much Dimas I’ve subscribed to feed, twitter, and facebook and will be posting about how awesome you are over on GeekEstate Blog – PR5!

  10. Sha

    Hey what should I use if I’m going to make visible a meta box in a specific page
    Thank You

  11. Johan

    Hi Dimas.
    I really appreciate your tutorials, i have one question for ya, is it possible to get this to update automatically when switching template?

    Thx !

  12. Johan

    Hi again

    Yeah now when i read it again its a pretty confusing question.

    Im doing this things in the function.php so when im saying update automatically i mean when your choosing page template design.

    So when choosing lets say the startpage template design i want a set of custom write panels to appear, right now i need to update it with either publish or save to draft before these feild appear.

    im thinking that this might be doable with some jquery and ajax?

    I would do this with custom post types but the thing is that custom post types rewrites the url structure.

    I hope this was better explained :)

  13. paul

    Hi Dimas

    Your examples above shows how to add metabox for a specific post id.

    Is it possible to make it specific to that post id AND any post that is a subpage of that post id too ?

  14. paul

    scratch that, I just saw your answer to Ross up there.

    anyway, Thank you for this wonderful script !

  15. Travis Smith

    This is great! However, the only downside to is that the user must save or update the page/post before the metabox appears. Is there any way to have this done via AJAX? Maybe set the metabox to auto-appear, add a filter to hide it (via default_hidden_meta_boxes hook), then uncheck it to have it auto appear? Just thinking out loud. Thoughts?

  16. Travis Smith

    I think if I use the hook, which hides it, but not via CSS. The CSS that hides it is .hide-if-js {display:none;}

    What the JS/jQ needs to do is select/unselect the checkmark in the screen options form (in .metabox-prefs).

    I’ve started a fiddle: http://jsfiddle.net/SAbxU/12/

    The JS does a good job of hiding/unhiding the metabox. However, I need it to check/uncheck the box at the top too.

Leave a Reply