Home › Forums › General Issues › Copy custom field to WordPress Editor field › Reply To: Copy custom field to WordPress Editor field
Thanks. That got me on the right track. If this can help anyone, here is how I did it. After I used phpmhyadmin to remove the fields I didn’t need. I didn’t concern myself with the excerpt because wp auto generates it.
$args = array( 'post_type' => 'custom_post_name', 'posts_per_page' => -1 );
$loop = new \WP_Query( $args );
$count = 1;
while ( $loop->have_posts() ) : $loop->the_post();
$legacy_content = get_field( 'legacy_content' );
$content = get_the_content();
// If custom content field is not empty and wordpress native content is empty
if ( !$legacy_content == '' && $content == '' ) {
$post_args = array(
'ID' => get_the_ID(),
'post_content' => $legacy_content, // update legacy content field to post_content
);
wp_update_post( $post_args );
update_field( 'legacy_content', '', get_the_ID() );
update_field( 'legacy_excerpt', '', get_the_ID() );
}
endwhile;
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.