## wp_insert_post does not insert string with apostrophes correctly

Question

I’m using wp_insert_post (for several reasons) in a script I’m writing and it’s causing any string that has an apostrophe in it to be truncated up to that character (including the character). Here’s the code I’ve got to test it:

$question = "If you’re in need, this is who you call"; echo$question."<br />";

$post = array( 'post_title' =>$question,
'post_status'    => 'publish',
'post_type'      => 'question'
);

echo $post['post_title'];$the_post_id = wp_insert_post(\$post);


It’s weird because when I echo out both the strings, the echo the correct thing on both ends so I’ve isolated it down to the wp_insert_post function that’s causing the issue. When I view it in WordPress, the title is just ‘If you’ and then ends.

I found a similar problem here:

http://premium.wpmudev.org/forums/topic/q-wp_insert_post-truncates-post-content-on-quotes-is-there-a-proper-way-to-escape-these-things


But there doesn’t seem to be any solution to it on that page. Any ideas on what’s going on here and how to solve it? No idea why it’s causing it. I’m looking into it to see if has something to do with something else in my code but it seems like it shouldn’t because the array element seems formatting just fine when it’s echoed out before the wp_insert_post() function.