How to Prevent WordPress to encode html in post

As as title, how to prevent wp not to encode html in a post?

currently i just need to prevent ‘&’ change to &
The result need to be looks like on editor with html tab mode selected.

Read More
$content = $wpdb->get_row("SELECT post_content FROM $wpdb->posts WHERE ID=xxx");
$content = str_replace('amp;','',$content->post_content);//remove amp;

$wpdb->query("UPDATE $wpdb->posts SET post_content = $content WHERE ID = xxx;");

but that code still encode the html.

update:
and also how to implement content filter(prevent to encode some text) in collaboration with wp_insert_post() function

update[SOLVED]: stackexchange

$content = get_post_field('post_content', XXX, 'raw');
$content = str_replace('amp;', '', $content);
$wpdb->update( $wpdb->posts, array( 'post_content' => $content ), array( 'ID' => XXX ) );

Related posts

Leave a Reply

1 comment

  1. <?php $content = htmlentities( html_entity_decode($content) ); ?>
    

    This code will print HTML tags, and then decode HTML entities (like &amp; to &).

    Oh, and with wp_insert_post(), do:

    // Create post object
    $my_post = array(
      'post_content' => $content,
      'post_id' => POST_ID # update the post with the same ID as POST_ID
    );
    

    You can use the escape function as a shortcode:

    function escape_html_func( $attrs, $content = "" ) {
      return htmlentities( html_entity_decode($content) );
    }
    add_shortcode( 'escape', 'escape_html_func' );
    

    like [escape]<span>Hello!</span>[/escape] in blog posts. Is this what you meant by content filter?