I have 5 ACF in every post, which split content in 5 chapters (chapter_1, chapter_2 and so on). Practically I’d like to take the content from the fields and move it into the post section keeping formatting and the rest. A solution would be to do it by hand but 400 posts would take quite a while. Is there a way to automate this? There is a similar topic in the forum with this code but I can’t seem to make it work. It only change the latest post before spitting an error.
$args = array(
'post_type' => 'YOURCUSTOMPOSTTYPE',
'posts_per_page' => -1,
'post_status' => 'any'
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
$custom_field_raw = get_the_content().get_field('YOURCUSTOMFIELD');
$custom_field_text_only = wp_strip_all_tags($custom_field_raw);
$my_post = array(
'ID' => get_the_ID(),
'post_content' => $custom_field_raw // use $custom_field_raw if you want to keep any HTML formatting
wp_update_post( $my_post );