Solution:
First, you need to register your meta box. You could use add_meta_boxes_page
hook.
add_action( "add_meta_boxes_page", "se20892273_add_meta_boxes_page" );
// Register Your Meta box
function se20892273_add_meta_boxes_page( $post )
{
add_meta_box(
'se20892273_custom_meta_box', // this is HTML id
'Metabox Title',
'se20892273_custom_meta_box', // the callback function
'page', // register on post type = page
'side', //
'core'
);
}
Then use the callback function to generate the template
function se20892273_custom_meta_box( $post )
{
// you will get the $post object
// do your stuff here
}
To save any input value used on your meta box, use ‘save_post_page’ hook.
add_action( "save_post_page", "se20892273_save_post_page" );
function se20892273_save_post_page( $post_ID )
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_ID ;
if( isset( $_POST['input_name'] ))
{
update_post_meta( $post_ID, '_w4_template', $_POST['input_name'] );
}
}