I have a problem with wp_insert_post.
When I’m attempting to insert my post, the post_content essentially shows up as just blanks spaces. I even went into MySQL to confirm. Everything else, post_title, post_excerpt, etc shows up just fine.
I did a print_r($this->postData) Just prior to passing this to wp_insert_post just to be sure it wasn’t empty and the right data was present.
The contents of the data are
<object> ... </object>
Would that be an issue?
Here’s my code that creates the $this->postData variable that’s passed into wp_insert_post.
$this->postData = array( 'post_content' => $this->jsonData['data'], 'post_title' => $this->jsonData['title'], 'post_excerpt' => $this->jsonData['description'], 'tags_input' => $this->jsonData['tags'], 'post_date' => date('Y-m-d H:i:s'), 'post_status' => 'publish', 'post_author' => 1, 'post_date_gmt' => date('Y-m-d H:i:s'), );
thanks in advance!
OK, SO this is what I found out, the data
was the culprit. WordPress sanitizes the input before committing to the database. Other non allowed tags include
I’ve seen this solution online
$postData = array( ... 'filter'=>true ... );
However, some people say that’s a security flaw. I dug a little deeper and I believe the best method I found out, seems to be this:
kses_remove_filters(); $id = wp_insert_post($postData); kses_init_filters();
'filter' => true,
I hope this helps everyone! 🙂