Skip to content
mengfung.com
til

wp_insert_post unslashes its input, so content with backslashes needs wp_slash first

 ·  1 min read

Inserting a post from PHP quietly turned [^\n] into [^n] in a code sample. wp_insert_post and wp_update_post expect slashed data and strip one level of backslashes. Wrap the array in wp_slash():

wp_update_post( wp_slash( array( 'ID' => $id, 'post_content' => $html ) ) );