Wordpress - Using TinyMce with textareas in meta boxes on custom post types
Here's a pastebin with your code included.
Get the old value of the tinyMCE
$meta_biography = get_post_meta( $post->ID, 'meta_biography', true );
Call the TinyMCE Editor
wp_editor( $meta_biography, 'biography', array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'meta_biography',
'textarea_rows' => 10,
'teeny' => true
) );
Save The Editor Value or if nothing is there - delete old values.
if( isset( $_POST['meta_biography'] ) && $_POST['meta_biography'] != '' ) {
update_post_meta( $post_id, 'meta_biography', $_POST['meta_biography'] );
} else {
delete_post_meta( $post_id, 'meta_biography' );
}
If you want to add more options to the editor - You can view the Codex or Check out this nice WPTuts Article. You want to use the tinymce
and pass it an array of settings. You might have to remove the teeny => true
in the wp_editor()
since the Codex says that it will only use minimal editor configuration.
// for pages use 'edit_page_form' as the first parameter. And see my comment below.
add_action( 'edit_form_advanced', 'my_meta_editor' );
function my_meta_editor() {
// set 'your_meta_key' to the actual key
$content = get_post_meta($post->ID, 'your_meta_key', true);
// only low case [a-z], no hyphens and underscores
$editor = 'mymetaeditor';
// See my comment below
$editor_settings = array();
wp_editor( $content, $editor, $editor_settings);
}
Search Administrative Actions for edit_form_after_title
, edit_form_after_editor
, edit_form_advanced
if you want to change the location of the meta box.
Also see wp_editor for editor settings.