I am using Magic Fields 2 for custom meta boxes and custom fields, but this situation pertains to any meta box.
I have a custom meta box that I want to display on only 3 specific page IDs.
function mf_1_remove_meta_boxes() {
if( !in_array($_GET['post'], array('194','185','2') ) ):
remove_meta_box( 'mf_1', 'page', 'normal' );
}
UPDATE
Using Bainternet’s solution, the code works. That being said, a new issue became apparent. When a new page is created, the meta box is visible immediately, then disappears once the page is saved, since the ID does not match an ID that has been specified.
UPDATE 2
The code above has been modified to correct the issue with the meta box appearing on a new (unsaved) page. It has also been modified to a complete and working code. The meta box will be removed for all users.
To remove the meta box for everyone except admins:
function mf_1_remove_meta_boxes() {
if( !is_admin())
return;
if( !in_array($_GET['post'], array('194','185','2') ) ):
remove_meta_box( 'mf_1', 'page', 'normal' );
}
A simple and cleaner solution would be to use !in_array ex:
this way you can just add the ids in the array and as many as you want
Try:
if($_GET['post'] != 194 || $_GET['post'] != 185 || $_GET['post'] != 2)
It should work like this.