0

After editing/styling i save the post and this doesn't keep the styling instead give me plain text.

        <?php
    $content = get_post_meta($post->ID,'principle_duties',true);
    $editor = 'principle_duties';
    $settings = [
        'textarea_rows' => 10,
    ];
    wp_editor($content,$editor,$settings);
     ?>
//////////////////
  if ( isset( $_POST['principle_duties'] ) ) {
        update_post_meta( $post_id, 'principle_duties', sanitize_text_field( $_POST[ 'principle_duties' ] ) );
    }

[edited one[1]

after save

3
  • Has the value of the meta principle_duties definitely got the HTML in it, at the time of fetching it from the database? Can you see HTML in the meta's value in the database?
    – Dan.
    Commented Nov 27, 2016 at 13:55
  • 1
    Please edit your question to include how you're saving principle_duties post meta.
    – Ismail
    Commented Nov 27, 2016 at 14:49
  • @SamuelElh updated the post. please check Commented Nov 27, 2016 at 17:27

1 Answer 1

1

You are stripping all HTML tags before saving principle_duties.

sanitize_text_field()

This function strips all HTML tags, so the value being stored has no HTML. That's why it's coming out as totally plain text.

To sanitize wp_editor I would use wp_kses().

See here on how to use it: https://codex.wordpress.org/Function_Reference/wp_kses

For the allowed HTML tags, you can simply pass the global variable $allowedposttags which I believe would be the same way WordPress does things with it's editor in posts/pages' content.

0

Your Answer

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

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