How to control the the behaviour of wp_insert_post?

I am using wp_insert_post to bulk insert posts into WordPress, according to http://codex.wordpress.org/Function_Reference/wp_insert_post it seems like the method does many tag manipulation for the content supplied, for example, it will replace a <br> tag if it finds a newline n character in the string. I wonder how could we turn this feature off, as in my case I have all the content pre-processed and I want WordPress take them as is. The kses_remove_filters() and 'post_content_filtered' => true, lines are my attempts to solve this problem, but it doesn’t seem to work.

kses_remove_filters();
$my_post = array(
'post_title' => wp_strip_all_tags($json_str['title'][0]),
'post_content' => $json_str['content'],
'post_date' => $json_str['pdate'],
'post_name' => $json_str['alias'][0],
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(2, $catid),
'post_content_filtered' => true,
);
wp_insert_post();

Related posts

Leave a Reply

1 comment

  1. From the documentation:

    wp_insert_post() passes data through sanitize_post(), which itself handles all necessary sanitization and validation (kses, etc.).

    In wp-includes/post.php line ~394, comment this line out:

    $_post = sanitize_post( $post, 'raw' );
    

    But it is generally a bad idea to hack core files.