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:
<?php
// meta box for news category
add_action('admin_init','news_init');
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,
Nadine
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.Just went a different way on this, didn’t end up using categories.
$post->post_category
is returning an ArraySo you shoul tes like this