"my-meta-box-{$i}", 'title' => sprintf( 'Slide %s', $i ), 'pages' => array( 'lom_slideshow','' ), // multiple post types 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( 'name' => 'Slide Title', 'desc' => 'Enter the title of the slide here', 'id' => $prefix . 'title', 'type' => 'text' ), //array( 'name' => 'Slide Description', 'desc' => 'Provide a brief description of the picture or video', 'id' => $prefix . 'textarea', 'type' => 'textarea' ), //plain text description array( 'name' => 'Slide Description', 'desc' => 'Provide a brief description of the picture or video', 'id' => $prefix . 'tinymce', 'type' => 'tinymce' ), array( 'name' => 'Slide Image', 'desc' => 'Choose the image', 'id' => $prefix . 'image', 'type' => 'select' ), //array( 'name' => 'Slide Image', 'desc' => 'Enter the URL of the image here', 'id' => $prefix . 'image', 'type' => 'text' ), //array( 'name' => 'Image upload', 'desc' => 'Upload an Image', 'id' => $prefix . 'img', 'type' => 'image' ), array( 'name' => 'Slide Embed Code', 'desc' => 'Insert embed code for the video', 'id' => $prefix . 'embed', 'type' => 'textarea' ), array( 'name' => 'Hide Slide', 'id' => $prefix . 'checkbox', 'type' => 'checkbox' ) ) ); } /********************************* Setup Class *********************************/ foreach ($meta_boxes as $meta_box) { $my_box = new My_meta_box($meta_box); } class My_meta_box { protected $_meta_box; // create meta box based on given data function __construct($meta_box) { if (!is_admin()) return; $this->_meta_box = $meta_box; // fix upload bug: http://www.hashbangcode.com/blog/add-enctype-wordpress-post-and-page-forms-471.html $current_page = substr(strrchr($_SERVER['PHP_SELF'], '/'), 1, -4); if ($current_page == 'page' || $current_page == 'page-new' || $current_page == 'post' || $current_page == 'post-new') { add_action('admin_head', array(&$this, 'add_post_enctype')); } add_action('admin_menu', array(&$this, 'add')); add_action('save_post', array(&$this, 'save')); } function add_post_enctype() { echo ' '; } /// Add meta box for multiple post types function add() { foreach ($this->_meta_box['pages'] as $page) { add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']); } } // Callback function to show fields in meta box function show() { global $post; // I added this here to setup the Attachments for the dropdown $images = array(); $attachments = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => null, 'post_status' => 'inherit', 'post_parent' => $post->ID ) ); // Use nonce for verification echo ''; echo ''; foreach ($this->_meta_box['fields'] as $field) { // get current post meta data $meta = get_post_meta($post->ID, $field['id'], true); echo '', '', ''; } echo '
'; switch ($field['type']) { case 'text': echo '', '
', $field['desc']; break; case 'textarea': echo '', '
', $field['desc']; break; case 'tinymce': array_push($mce_ids, $field['id']); echo '', '
'; echo $field['desc']; break; // This is my attempt to get to get the Attachments to populate the
', '
'; // If we have accumulated any TinyMCE type items, then active TinyMCE on them if (count($mce_ids) > 0) { ?> _meta_box['fields'] as $field) { $name = $field['id']; $old = get_post_meta($post_id, $name, true); $new = $_POST[$field['id']]; if ($field['type'] == 'file' || $field['type'] == 'image') { $file = wp_handle_upload($_FILES[$name], array('test_form' => false)); $new = $file['url']; } if ($new && $new != $old) { update_post_meta($post_id, $name, $new); } elseif ('' == $new && $old && $field['type'] != 'file' && $field['type'] != 'image') { delete_post_meta($post_id, $name, $old); } } } } ?>