If your tests are correct the problem is with the data in $csv_data
. Before saving something to the database WP runs a lot of filters. Some are standard, others may be added by plugins. So, most likely some piece of code thinks the content of $csv_data
is not fit to be stored in the database.
You may try to track this down. Or you could bypass the filters. Only do this when you are very sure about what is in $csv_data
.
Right before a post is actually updated (so, after the data has passed all sanitation filters) wp_insert_post
offers a final possibility to filter the data in this line:
$data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr, $update );
So, you can build a filter to replace the sanitized content with the one that was originally passed to the function, which is stored in $unsanitized_postarr
:
function wpse424390_restore_content ($data, $postarr, $unsanitized_postarr, $update) {
$data['post_content'] = $unsanitized_postarr['post_content'];
return $data;
}
Now, you don’t want this filter to be present all the time, because then it would trigger at every save action. You would use add_filter('wp_insert_post_data','wpse424390_restore_content',10,2)
right before your call to wp_update_post
and remove_filter('wp_insert_post_data','wpse424390_restore_content')
directly after.