I'm working on writing a script to import data from a custom CMS into Wordpress. As part of this, I need to import the post content exactly, without modifying anything. However, some of the posts contain HTML comments which contain tags, and this seems to be confusing Wordpress.
I've distilled my script down into a small representative example:
<?php $_SERVER['HTTP_HOST'] = 'localhost'; require_once('/var/www/wordpress/wp-load.php'); $post = array( 'post_content' => 'This is <!-- a comment -->', 'post_status' => 'publish' ); wp_insert_post($post);
This works fine, and I get exactly what you would expect. If I view the source of the post in my browser, I get:
<div class="entry-content"> <p>This is <!-- a comment --></p> </div><!-- .entry-content -->
But if my comment contains tags in it (for example, replace the
This is <!-- <p>a comment</p> -->), Wordpress escapes the comment delimiters and parses the tags inside. The comment becomes visible, and when I view source, it looks like this:
<div class="entry-content"> <p>This is <!– <p>a comment</p> <p> –></p> </div><!-- .entry-content -->
How can I prevent Wordpress from breaking the comment delimiters and parsing the tags inside? For the record, I'm on Wordpress 3.3.1 in Ubuntu 12.04.
EDIT: Just tried it on Wordpress 3.4; the problem still occurs.