Is there a way to get N number of WYSIWYG editors in a custom post type?

Say your custom post type was called Properties, you would add the box to hold your additional tinyMCE editor using code similar to this:

function register_meta_boxen() {
    add_meta_box("wysiwyg-editor-2", "Second Column", "second_column_box",
    "properties", "normal", "high");    
}
add_action('admin_menu', 'register_meta_boxen');

wysiwyg-editor-2 is the ID that the meta box will have applied to it, Second Column is the title that the meta box will have, second_column_box is the function which will print out the HTML for the meta box, properties is our custom post type, normal is the location of the meta box, and high specifies that it should be shown as high in the page as possible. (Usually below the default tinyMCE editor).

Then, taking this as the most basic example, you must attach the tinyMCE editor to a textarea. We still have to define our second_column_box function which will print the HTML for the meta box so this is as good a place as any to do this:

function second_column_box() {
    echo <<<EOT
    <script type="text/javascript">
jQuery(document).ready(function() {
    jQuery("#tinymce").addClass("mceEditor");
    if ( typeof( tinyMCE ) == "object" &&
         typeof( tinyMCE.execCommand ) == "function" ) {
        tinyMCE.execCommand("mceAddControl", false, "tinymce");
    }
});
</script>
    <textarea id="tinymce" name="tinymce"></textarea>
EOT;
}

There are a couple of issues which I’m not sure of how to overcome. The tinyMCE editor will be nested inside of a metabox, which might not be ideal, and it will not feature the ability to switch between HTML and Visual editing modes, as well as the the media insertion commands which the normal post editor has. Switching the modes appears to be defined as a function who’s first argument is the ID, but yet it also appears to coded into the wp-tinymce script. It is possible to use the built in tinyMCE functions to do so, but this changes the textarea between full tinyMCE and a basic textarea, without any of the WP HTML insertion buttons.

Leave a Comment