Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

$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;");

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

but that code still encode the html.

share|improve this question
add comment

2 Answers 2

Save post when in HTML tab of editor. It should be saved as close to what you see in editor as possible. I had run couple of quick tests and ampersands are not encoded in this case (as you want to).

I am not sure how to prevent this for visual editor, because a lot of formatting-related stuff in editor is handled by JavaScript rather than PHP.

Update

Cleaning up your snippet, this seems to work:

$content = get_post_field('post_content', XXX, 'raw');
$content = str_replace('amp;', '', $content);
$wpdb->update( $wpdb->posts, array( 'post_content' => $content ), array( 'ID' => XXX ) );
share|improve this answer
    
Yes i can do it in editor, but i need to run in my code. –  user3135 Feb 14 '11 at 10:47
    
WOW.. Its working, thank you. The key is 'raw' right? Thank you Rarst –  user3135 Feb 14 '11 at 12:02
add comment

IMHO, the simplest way to achieve this behaviour is by using a plugin to forcibly save and recall your editor input as raw (and not interpret it upon save/publish); there are a few available in the WP plugins directory but most have particular 'quirks' as to their usage or implementation.

I had particular problems with embedding YouTube and other video/audio players until I utilised a raw HTML plugin.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.