Home › Forums › General Issues › Migrate content from ACFs to the_content › Reply To: Migrate content from ACFs to the_content
Ok, I swapped $my_post
for $post
as advised and now the content is copied over but in 2-3 instances. It’s like if the loop happens multiple times before settling.
The code looks like this now:
<?php
global $post;
$args = array(
'post_type' => 'post',
'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('chapter_1');
$custom_field_text_only = wp_strip_all_tags($custom_field_raw);
$post = array(
'ID' => get_the_ID(),
'post_content' => $custom_field_raw
);
wp_update_post( $post );
endforeach;
wp_reset_postdata();
Ideally I’d need to move all chapters at once and make sure the loop doesn’t create multiple instances of every field. Could you help, please?
THANK YOU!
EDIT:
I’m using this to add PHP to the page: https://wordpress.org/plugins/insert-php-code-snippet/
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.