Steven
Steven

Reputation: 19425

Not able to add meta boxes to multiple post types

For some reason, I'm not able to add meta boxes to multiple post types. According to the documentation, I should be able to use an array of post types.

This works:

add_meta_box( 
  'Bilder', 
  __('Bilder'), 
  'project_custom_meta_box_images',
  'page', // <---- works
  'normal', 
  'default' 
);

And this does not work:

add_meta_box( 
  'Bilder', 
  __('Bilder'), 
  'project_custom_meta_box_images',
  array('page', 'post'),  // <---- does not work
  'normal', 
  'default' 
);

Can anyone see what I'm doing wrong?

Upvotes: 0

Views: 94

Answers (1)

henrywright
henrywright

Reputation: 10240

Further to @koala_dev's comment, try using a foreach loop:

$types = array( 'post', 'page' );
foreach ( $types as $type ) {
    add_meta_box( 
        'Bilder', 
        __('Bilder'), 
        'project_custom_meta_box_images',
        $type,
        'normal', 
        'default' 
    );
}

Upvotes: 1

Related Questions