'Featured Video Embed Code', 'desc' => 'Paste your video code here to show a video instead of a featured image.', 'id' => $prefix . 'video_embed', 'type' => 'textarea' ) // array( // 'label'=> 'Textarea', // 'desc' => 'A description for the field.', // 'id' => $prefix.'textarea', // 'type' => 'textarea' // ), // array( // 'label'=> 'Checkbox Input', // 'desc' => 'A description for the field.', // 'id' => $prefix.'checkbox', // 'type' => 'checkbox' // ), // array( // 'label'=> 'Select Box', // 'desc' => 'A description for the field.', // 'id' => $prefix.'select', // 'type' => 'select', // 'options' => array ( // 'one' => array ( // 'label' => 'Option One', // 'value' => 'one' // ), // 'two' => array ( // 'label' => 'Option Two', // 'value' => 'two' // ), // 'three' => array ( // 'label' => 'Option Three', // 'value' => 'three' // ) // ) // ) ); // Field Array (Posts Meta) $pageflow_post_meta_fields = array( array( 'label' => 'Featured Video Embed Code', 'desc' => 'Paste your video code here to show a video instead of a featured image.', 'id' => $prefix . 'video_embed', 'type' => 'textarea' ) ); // The Callback for page meta box function pageflow_show_custom_meta_box() { global $pageflow_meta_fields; pageflow_show_page_meta_box($pageflow_meta_fields); } // The Callback for post meta box function pageflow_show_custom_post_meta_box() { global $pageflow_post_meta_fields; pageflow_show_page_meta_box($pageflow_post_meta_fields); } // The Callback function pageflow_show_page_meta_box($meta_fields) { global $post; // Use nonce for verification echo ''; // Begin the field table and loop echo ''; foreach ($meta_fields as $field) { // get value of this field if it exists for this post $meta = get_post_meta($post->ID, $field['id'], true); // begin a table row with echo ''; } // end foreach echo '
'; switch ($field['type']) { // text case 'text': echo '
' . $field['desc'] . ''; break; // textarea case 'textarea': echo '
' . $field['desc'] . ''; break; // checkbox case 'checkbox': echo ' '; break; // select case 'select': echo '
' . $field['desc'] . ''; break; } //end switch echo '
'; // end table } // Save the Data function pageflow_save_custom_meta($post_id) { global $pageflow_meta_fields; global $pageflow_post_meta_fields; // verify nonce if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) return $post_id; // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) return $post_id; } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } //either post or page fields we'll be working with $fields; // Check permissions (pages or posts) if ('page' == $_POST['post_type']) { $fields = $pageflow_meta_fields; } else if ('post' == $_POST['post_type']) { $fields = $pageflow_post_meta_fields; } // loop through fields and save the data foreach ($fields as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } } // end foreach } add_action('save_post', 'pageflow_save_custom_meta');