In my plugin I want to display an add_meta_box under the WYSISWYG in the new post page, which is no problem and works fine.
But the box should only appear when a specific category (example: category with id = 5) is selected, otherwise it is not visible.
How can this be achieved?
Edit as requested in the comments here is my jquery:
$script = "
<script type='text/javascript'>
jQuery(document).ready(function($) {
$('#metabox_sectionid').hide();
$('#in-category-".CATEGORY."').is(':checked') ? $('#metabox_sectionid').show() : $('#emetabox_sectionid').hide();
$('#in-category-".CATEGORY."').click(function() {
$('#metabox_sectionid').toggle(this.checked);
});
});
</script>";
echo $script;
BR & Thanks,
mybecks
You could try this:
get the ID’s of the attached categories and wrap your add_meta_box function inside a simple test against your defined cat ID.