Return to Snippet

Revision: 47810
at June 16, 2011 17:53 by xavsio4


Initial Code
$meta_box = array(
    'id' => 'my-meta-box-1',
    'title' => 'Custom meta box 1',
    'pages' => array('post', 'page', 'link'), // multiple post types, accept custom post types
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
        array(
            'name' => 'Text box',
            'desc' => 'Enter something here',
            'id' => $prefix . 'text',
            'type' => 'text',
            'std' => 'Default value 1'
        )
    )
);

/ Add meta box
function mytheme_add_box() {
    global $meta_box;

    foreach ($meta_box['pages'] as $page) {
        add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $page, $meta_box['context'], $meta_box['priority']);
    }
}

Initial URL
http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html

Initial Description
This function will loop all the registered post types, and for each post type create a meta box with given data. Here links is assimilated to post types

Initial Title
Add a metabox to multiple posts

Initial Tags
wordpress

Initial Language
PHP