How to add a Custom Meta Box for more than one Post Type?

I am using the following code in functions.php for adding a custom meta box.

The custom post type is themes. I want to add more post types, how can I?

add_meta_box( 
    'my-meta-box-id', 
    'Demo & Download', 
    'cd_meta_box_cb', 
    'themes', 
    'normal', 
    'high' 
);

Related posts

Leave a Reply

1 comment

  1. Whenever in doubt about a WordPress function, consult the Codex.
    http://codex.wordpress.org/Function_Reference/add_meta_box

    There, you’ll see that you need to add one meta box to each post type.

    add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );
    
    function myplugin_add_custom_box() {
        add_meta_box( 
            'myplugin_sectionid',
            __( 'My Post Section Title', 'myplugin_textdomain' ),
            'myplugin_inner_custom_box',
            'post' 
        );
        add_meta_box(
            'myplugin_sectionid',
            __( 'My Post Section Title', 'myplugin_textdomain' ), 
            'myplugin_inner_custom_box',
            'page'
        );
    }