How to pass variable via $callback_args for add_meta_box
I am trying to pass a variable to the callback function through add_meta_box
. I know that there is $callback_args
that can be used to pass the variable. But somehow I just can't get it to work within a class. This is my code:
class myclass{
//...blah blah...adding action
function add_ex_field() {
add_meta_box(
'apextadmin',
__( 'My Custom Field', 'myplugin_textdomain'),
array($this,'the_callback_function'),
post,
//the $param is some value that is saved in my option table.
array('test' = $param)
);
}
//do I need to include these two parameters? because they gave me error!
function the_callback_function($post, $metabox){
echo 'h1testing field/h1';
echo $metabox['args']['test'];
}
}
global $myclass;
$myclass = new myclass();
Thanks.