I'm having issues creating an import / caching script to be used within a WordPress site. This feed comes from a single text file that is then parsed and returned as an array.
When running through each item from the feed I am using the wp_insert_post function to add in the data (see below):
$post = array( 'post_title' => $property['DISPLAY_ADDRESS'], 'post_name' => sanitize_title($property['DISPLAY_ADDRESS'] . "-" . $property['AGENT_REF']), 'post_content' => $content, 'post_status' => 'publish', 'post_type' => 'property', 'page_template' => 'page-property.php' ); $post_id = wp_insert_post( $post, true );
When I output the $post_id to catch the error I get the below:
WP_Error Object ( [errors] => Array ( [db_update_error] => Array ( [0] => Could not update post in the database ) ) [error_data] => Array ( ) )
I have tried taking the actual text that is in the $content varilable and adding that straight into the 'post_content' option and that works fine. It is somewhere between my text and it being passed as $content that is causing issues. I have also tried using the 'post_content_filtered' option, which didn't make a difference.
Has anyone had this issue before or know why this error will be triggered? Without the 'post_content' field it works fine.
*** UPDATED ***
The $content variable contains text from the feed. Shown below with some data blanked out as its for a client. Below is an example of $post outputted to show the data.
Array ( [post_title] => Example Post Title [post_name] => example-post-name [post_content] => ***£303.33 pcm*** Available 1st July Rent includes all utility bills. A self contained room with your own kitchenette and shared bathroom with one other . A popular location close shops and all main roads . [post_status] => publish [post_type] => property [page_template] => page-property.php [post_content_filtered] => )
$content
empty?Could not update post in the database
error if you're passingID
to update an existing post. Something doesn't seem right here if you're not setting that and getting this error.