Support

Account

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/