The auestion is, why my foreach loop renders metabox only with information from last array? The code of class:
class CusomMetaBox {
/**
* Hook into the appropriate actions when the class is constructed.
*/
//public function __construct( $post_type, $unicname, $headline, $fieldDisc ) {
public function __construct( $array ) {
global $post;
foreach ( $array as $metabox ) {
$this->post_type = $metabox['post_type'];
$this->unicname = $metabox['unicname'];
$this->headline = $metabox['headline'];
$this->fieldDisc = $metabox['field_desc'];
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
add_action( 'save_post', array( $this, 'save' ), 1, 2);
}
}
here a goes other methods that render and save metaboxes...
public function add_meta_box() {
add_meta_box(
$this->unicname
,$this->headline
,array( $this, 'render_meta_box_content' )
,$this->post_type
,'advanced'
,'high'
);
}
This is function from functions.php that initialize the class:
function call_createCustomMetaBox() {
new CusomMetaBox( array(
'eventdata'=>array(
'post_type'=>'event',
'unicname'=>'eventdata',
'headline'=>'Event Date',
'field_desc'=>'Enter the date of your event'
),
'eventplace'=>array(
'post_type'=>'event',
'unicname'=>'eventplace',
'headline'=>'Place of the event',
'field_desc'=>'Enter address of the event'
),
'productcost'=>array(
'post_type'=>'product',
'unicname'=>'productcost',
'headline'=>'Cost of the product',
'field_desc'=>'Enter the cost of the product. For example: 50.00$ per hour'
)
) );
}
I cant figrue out, why i got only 1 meta box instead of 3 (2 in event post and 1 in product post) ?