I got a client requirement where the editing facilities available in wordpress had to be available for content that was meant to be displayed on the sidebar of a particular post/page.

The content to be displayed was implemented originally using metaboxes which contained a single textarea where content was input as raw HTML and did not have insert/upload facilities.

I have decided to migrate this design to use wp_editor() as it gives all the wordpress native editing facilities (without using a metabox as it is not recommended). But I am not sure how to get the entered data and POST it to the backend and then tie into the following action to save the data:

add_action( 'save_post', 'save_sidebar_content' );

I was also using the following helper functions:


I would like to know if there are any such functions to ease the CRUD operations related to this data when using wp_editor().

Thanks in advance. nav


It works just the same like a regular textarea with the exception of the data being escaped so when you call for the saved data just make sure to decode the html entities using html_entity_decode here is a very simple demo class, take a look at how the field is created.

if (!class_exists('wp_editor_meta_box')){
        class wp_editor_meta_box{

                public function __construct(){
                        /* Define the custom box */
                        add_action( 'add_meta_boxes', array($this,'wp_editor__add_custom_box' ));

                        /* Do something with the data entered */
                        add_action( 'save_post', array($this,'wp_editor__save_postdata' ));

                /* Adds a box to the main column on the Post and Page edit screens */
                function wp_editor__add_custom_box() {
                                __( 'WP Editor Box' ),

                /* Prints the box content */
                function wp_editor_meta_box( $post ) {

                        // Use nonce for verification
                        wp_nonce_field( plugin_basename( __FILE__ ), 'wp_editor_nonce' );

                        $field_value = get_post_meta( $post->ID, '_wp_editor_', false );
                        wp_editor( html_entity_decode($field_value), '_wp_editor_' );

                /* When the post is saved, saves our custom data */
                function wp_editor__save_postdata( $post_id ) {

                        // verify if this is an auto save routine. 
                  // If it is our form has not been submitted, so we dont want to do anything
                  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 

                  // verify this came from the our screen and with proper authorization,
                  // because save_post can be triggered at other times
                  if ( ( isset ( $_POST['wp_editor_nonce'] ) ) && ( ! wp_verify_nonce( $_POST['wp_editor_nonce'], plugin_basename( __FILE__ ) ) ) )

                  // Check permissions
                  if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] )  ) {
                        if ( ! current_user_can( 'edit_page', $post_id ) ) {
                        else {
                                if ( ! current_user_can( 'edit_post', $post_id ) ) {

                  // OK, we're authenticated: we need to find and save the data
                        if ( isset ( $_POST['_wp_editor_'] ) ) {
                                update_post_meta( $post_id, '_wp_editor_', $_POST['_wp_editor_'] );

        }//end class
}//end if

new wp_editor_meta_box();
  • Thank you very much @Bainternet. Looks like have been a little mislead by WP saying that wp_editor() should not be used in metaboxes. Then again this is only a problem if I intend to move the metaboxes which is not going to happen in my case. Thanks, nav – navanitachora Apr 21 '12 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.