This is a jQuery solution based on this answer of mine.
The array with the page IDs must be adapted to your needs. There is a console.log
being dumped for easy checking.
In this example, the Featured Image meta box is being addressed, #postimagediv
. This also has to be adapted to your custom meta box Div ID.
add_action('admin_head', 'wpse_56059_script_enqueuer');
function wpse_56059_script_enqueuer()
{
global $current_screen;
if('page' == $current_screen->id)
{
echo <<<HTML
<script type="text/javascript">
jQuery(document).ready( function($) {
// The page IDs to check for
var arr = [ "21", "28" ];
/**
* Adjust visibility of the meta box at startup
*/
value = $('#parent_id').val();
if($.inArray(value,arr) > -1) {
// show the meta box
$('#postimagediv').show();
} else {
// hide your meta box
$('#postimagediv').hide();
}
// Debug only
// - outputs the ID of the selected page parent
// - checking for console existance to avoid js errors in non-compliant browsers
if (typeof console == "object")
console.log ('default value = ' + value);
/**
* Live adjustment of the meta box visibility
*/
$('#parent_id').live('change', function(){
value = $(this).val();
if($.inArray(value,arr) > -1) {
// show the meta box
$('#postimagediv').show();
} else {
// hide your meta box
$('#postimagediv').hide();
}
// Debug only
if (typeof console == "object")
console.log ('live change value = ' + value);
});
});
</script>
HTML;
}
}