• I have a meta box that uses tinyMCE instead of a plain textarea, but all html tags I use are simply being passed as text instead of correctly rendered on the page. Seems to be a filters issue, but I have no idea where to apply filters in the meta box functions. I would basically like to use exactly the same filters and html decoding in this meta box as are used in the post’s main tinyMCE-powered text area.

    I added tinyMCE using this code:

    $value = get_post_meta( $post->ID, 'new_field', true );
    $editor_id = 'new_field';
    $settings = array( 'media_buttons' => false );
    wp_editor( $value , $editor_id, $settings );

    When saving I apply esc_textarea:

    $my_data = esc_textarea( $_POST['new_field'] );

    Sometime between that and the page, the HTML tags just get ignored. Any suggestions appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You don’t need to apply filters unless you plan on other developers extending your code. Simply call the functions added to a filter directly when you save the content. Which functions are these? Unfortunately, I don’t know. It will take a fair amount of investigation to determine what the post editor does with content.

    That’s not really your immediate problem. Not having HTML recognized really is a problem. Rather than needing to add filters or their respective functions, it sounds like something needs to be removed. If there are HTML tags in your content, your browser will process them. If this is not happening, then what appears to be tags are not really tags. I think something is converting less than signs ‘<‘ into the HTML entity & lt;, and probably other conversions as well.

    Ideally, you would want to remove whatever is doing this. If you cannot, you could at least reverse the process. Your content is likely passed through htmlentities(). This can be reversed with html_entity_decode(). There’s other similar functions, you would want to use the exact reverse function, but determining that could be difficult.

    I realize I’ve not given you any usable answers, but hopefully I’ve shed light on what’s happening and possible avenues of investigation.

    Vincent

    (@vincentastolfi)

    I just wanted to comment to confirm that the suggestion by bcworkz is in fact the solution.

    wp_editor( html_entity_decode(bankruptcy_details_get_meta('bankruptcy_details_case_details')), 'bankruptcy_details_case_details', $settings = array() );

    I had to insert that html_entity_decode() function both when I was calling the meta box wpeditor’s content in the backend (on the post type’s post edit page itself) AS WELL AS when displaying it on the front end. I’ve also got it running when it saves the data in the database, using the update_post_meta function, just to make doubly sure that the database is storing the data as HTML.

    Thanks for this I’ve been looking everywhere for a solution!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘html tags in tinyMCE meta box not being encoded on page’ is closed to new replies.