WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to limit a meta_box to posts in a specific category. I'm using this method: http://www.farinspace.com/page-specific-wordpress-meta-box/ and it works rather well But I can't seem to get it to work with categories. Heres' my code:

// meta box for news category

function news_init(){

    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;

    $post = get_post($post_id);

    if ($post->post_category == '6'){
    add_meta_box('news_details', 'News Details', 'news_details', 'post');

I feel like I'm missing a step. Thoughts or ideas?

Thank you,


share|improve this question

You might want to check out his other post: http://www.farinspace.com/show-hide-meta-box-by-category/

I figure you would need some javascript because if you change categories, you would need some way for the browser to trigger to show the metabox, hence javascript.

He has a video tutorial, so that should help explain everything. Also, since you are already reading his blog, you might want to try out his WPAlchemy_MetaBox Class. I use it every time in my themes and I love it.

share|improve this answer
Yeah I can give that a shot, I looked it over before. re: the second post, but I'm just wondering if there's a more straight-forward way to do this using just a method of "find the Category ID of this post" – Nadine Feb 21 '12 at 23:55
up vote 0 down vote accepted

Just went a different way on this, didn't end up using categories.

share|improve this answer
Could you explain why/how you made that decision, so future visitors will gain knowledge? – GavinR Feb 27 '12 at 16:34

$post->post_category is returning an Array So you shoul tes like this

if ($post->post_category[0] == '6'){
   add_meta_box('news_details', 'News Details', 'news_details', 'post');
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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