Support

Account

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;