Skip to content

Instantly share code, notes, and snippets.

@karellm
Created November 7, 2012 23:41
Show Gist options
  • Save karellm/4035403 to your computer and use it in GitHub Desktop.
Save karellm/4035403 to your computer and use it in GitHub Desktop.
Meta box definition
The first is my definition. As you can note, there is a 'templates' argument. The problem was there before I added this.
I added what I changed to the inc/classes/meta-box.php to make the metabox definition check for the template used. It is very useful to have metabox on some pages only.
$meta_boxes[] = array(
// Meta box title - Will appear at the drag and drop handle bar. Required.
'title' => 'Sidebar',
// Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
'pages' => array( 'page' ),
// Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
'templates' => array( 'page-sidebar.php' ),
// Where the meta box appear: normal (default), advanced, side. Optional.
'context' => 'normal',
// Order of meta box: high (default), low. Optional.
'priority' => 'high',
// List of meta fields
'fields' => array(
array(
'name' => 'Sidebar',
'id' => "sidebar",
'type' => 'wysiwyg',
'std' => '',
// Editor settings, see wp_editor() function: look4wp.com/wp_editor
'options' => array(
'textarea_rows' => 4,
'teeny' => true,
'media_buttons' => false,
),
),
)
);
// on line 59
// Only on the specified templates
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if(isset($this->meta_box['templates']) && !in_array($template_file, $this->meta_box['templates'])) return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment