admin管理员组文章数量:1426243
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
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
Share
Improve this question
asked May 24, 2019 at 9:40
Michael RogersMichael Rogers
5498 silver badges37 bronze badges
2 Answers
Reset to default 1First 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 );
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/forums/topic/migrate-a-custom-field-content-to-the_content/
本文标签: databaseHow to copy data from a custom field to the postcontent
版权声明:本文标题:database - How to copy data from a custom field to the post_content? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745461268a2659334.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论