0

i used ACF to store post data in custom fields. i'd like to copy the data from a wysiwyg field to post_content into wp_posts table. How can i do this?

Roughly:

data is on wp_postmeta table, where meta_key = 'description' and post_id is = $post->ID
and needs to be copied over to 'post_content' of wp_posts table where id is = $post->ID
0

First get data from wp_postmeta table

$description = get_post_meta( $post->ID, 'description', true );

Try following code to update content

$my_post = array(
  'ID'           => $post->ID,
  'post_content' => $description,
);

 //Update the post into the database
 wp_update_post( $my_post );
0

Putting together a working example of @Parthavi Patel answer. This is a page template. When the page loads the code is executed. If there's too many posts it would be good to use a conservative value on posts_per_page and adjust the offset parameter after each batch is executed.

        <?php
/*
 * Template Name: experiments
 * Template Post Type: page
 */

global $post;
$args = array( 
    'post_type' => 'YOUR_CPT_HERE', 
    'posts_per_page' => -1,
    'post_status' => 'publish'
);

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );

    $custom_field_raw = get_field('YOUR_CF_HERE');

    //speedup by skip processing when CF is empty 
    if ($custom_field_raw != '') {

    $my_post = array(
        'ID'           => get_the_ID(),
        'post_content' => $custom_field_raw
    );

    wp_update_post( $my_post );

    }

endforeach; 
wp_reset_postdata();

?>

Reference/Source/Credits: https://support.advancedcustomfields.com/forums/topic/migrate-a-custom-field-content-to-the_content/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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