0

I have used wp_editor as a meta box for additional contents. Although it saves and displays the content, it does not save the format. Meaning, heading and paragraph tags are saved as simple text format. It ignores the HTML formats (heading, list, paragraphs) while saving.

Could anyone help me with some directions? I am stuck.

Thanks. I used the following code to register the metabox

class my_metaboxes{

    public function __construct() {
        add_action( 'add_meta_boxes', array( $this, 'my_overview_metabox' ) );
        add_action( 'save_post', array( $this, 'my_content_save' ) );
    }

    public function my_overview_metabox(){
        add_meta_box( 
            'page_overview_metabox', 
            'Page content overview', 
            array( $this,'content_overview_metabox' ), 
            'post', 
            'advanced', 
            'high' 
        );
    }

    public function content_overview_metabox( $post ) {
        wp_nonce_field( 'content_overview_save', 'content_overview_nonce' );
        $value = get_post_meta( $post->ID, '_post_content_key', true );

        echo '<input type="text" id="page_content_overview_metabox" name="page_content_overview_metabox" value="' . 
     esc_attr( $value ) . '" placeholder="Enter the page overview details" style="width: 100%; height:120px;">';

    }

    public function my_content_save( $post_id ){
       if ( ! isset($_POST['content_overview_nonce'])){
            return;
       }

       if ( ! wp_verify_nonce( $_POST['content_overview_nonce'], 'content_overview_save' ) ) {
            return;
       }

       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
       }

       if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return;
       }

       if ( !isset( $_POST['page_content_overview_metabox'] ) ) {
            return;
       }

       $my_data = sanitize_text_field( $_POST['page_content_overview_metabox'] );
       update_post_meta( $post_id, '_post_content_key', $my_data );
       }
}

new my_metaboxes();
2
  • Does that mean that your previous question is solved already? And please stop using the tag wordpress.com unless your site is hosted there. :)
    – fuxia
    Commented May 6, 2017 at 19:36
  • No it was not solved.
    – jeff
    Commented May 6, 2017 at 19:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.