How to add metabox for post of specific category

Instead of if ($post_id->post_category[0] == 18) try

if ( $post_id && in_category( 18, $post_id ) )

Also the 'save_post' action should be

 add_action('save_post','my_meta_save', 10, 2);

If you want the metabox to appear on a new post when the category is selected, then remove the outer category test if statement so that the metabox is always added and then show/hide using jquery (put this after the echo of the textarea)

echo '<textarea name=_designation rows="6" cols="100">'.$designation.'</textarea>';
?>
<script type="text/javascript">
jQuery(document).ready(function() {
    (function ($) {
        $('#in-category-18').change(function () { $('#team_meta').toggle(this.checked); }).change();
    })(jQuery);
});
</script>
<?php

Leave a Comment