0

Problem: I imported posts from an old Wordpress site to a new Wordpress site. Previous developer used an ACF field in replace of the Wordpress content-editor on post pages. I want to transfer the contents from the ACF field to the content-editor.

1 Answer 1

0

Solution: Add this to functions.php and refresh admin once. Remove after.

function process_post() {
    $my_posts = get_posts( array('post_type' => 'page', 'posts_per_page' => -1 ) );
    foreach ( $my_posts as $my_post ) :
        $value = get_field('course_content', $my_post->ID );
        if($value):
            $update_post = array(
                'ID'           => $my_post->ID,
                'post_content' => $value
            );
            wp_update_post( $update_post );
        endif;
    endforeach;
}
add_action( 'init', 'process_post' );

 

I also noticed that some fields were visible to the backend but not rendering on the site. Perhaps some type of database cache. I fixed this by refreshing the field values with similar logic:

function process_post() {
    $my_posts = get_posts( array('post_type' => 'page', 'posts_per_page' => -1 ) );
    foreach ( $my_posts as $my_post ) :
        $value = get_field('field_560094b2af64e', $my_post->ID );
        if($value):
            update_field( 'field_560094b2af64e', $value, $my_post );
        endif;
    endforeach;
}
add_action( 'init', 'process_post' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.