Below is some code I have for meta boxes, is there any specific way to limit this to a single page template like template-servicesinner.php
or page-plain.php
?
$prefix = 'tga_';
$meta_boxes[] = array(
'id' => 'project-box-1', // meta box id, unique per meta box
'title' => 'Project Box 1', // meta box title
'pages' => array('page'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(
array(
'name' => 'Review thumbnail',
'desc' => 'Only insert a thumbnail for you review here if you are showing reviews on the homepage (thumbnail should be at least 600x300px). Insert full path to the image, eg. http://yoursite.com/thethumb.jpg',
'id' => $prefix . 'review_thumb',
'type' => 'text',
'std' => ''
),
Yes, there is. And the most user friendly way is done with jQuery. You'll have to listen to changes in the dropdown
#page_template
. And make the same function run at page load, if template == something, show/hide the meta box.The scripts are loaded with
wp_footer-$hook
oradmin_print_scripts-$hook
. It has been covered in the following Wordpress Answers:Custom meta box shown when template is chosen
Toggle admin metabox based upon chosen page template
The hiding/showing of the metabox requires selecting 'Update' after changing the drop-down field.
Just update lines 6 and 7 as desired.