I was looking for a way to attach a custom meta box to the edit screen of a page at a specific template.
I found and tried this here and from my actual point of view this can't work that way. Let me explain why I think so: To determine, whether I'm on a screen using a specific template I need reference the global $post. But since this function to create the meta box is hooked into the admin_init the global $post will not yet exist.
So it has to put out an Error message, doesn't it? After those thoughts I tried to tie my meta_box_init function to edit_post, save_post and such. But the codex says, even they need $post to be set. So how could I achieve my page template specific meta box, really? Is there a clean solution?
global $post; if('your-template.php' == wp_basename( get_page_template() ) {//do metabox stuff here};
.if ($template_file == 'home.php')
.