I have this code

function add_custom_meta_box() {
add_meta_box(
    'custom_meta_box', // $id
    'Custom Meta Box', // $title 
    'show_custom_meta_box', // $callback
     'page', // $page    
    'normal', // $context
    'high'); // $priority
}
add_action('add_meta_boxes', 'add_custom_meta_box');

I want to add more post type like page,post,custom_post_type in this code

  'page', // $page 

How should I rewrite my code?

2 s
2

Define an array of post types, and register the metabox for each one separately:

function add_custom_meta_box() {

    $post_types = array ( 'post', 'page', 'event' );

    foreach( $post_types as $post_type )
    {
        add_meta_box(
            'custom_meta_box', // $id
            'Custom Meta Box', // $title 
            'show_custom_meta_box', // $callback
             $post_type,
            'normal', // $context
            'high' // $priority
        );
    }
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *