如何将数据从自定义字段复制到POST_CONTENT? 时间:2019-05-24 作者:Michael Rogers 我用过ACF 在自定义字段中存储post数据。我想从wysiwyg field 将\\u内容发布到wp\\u posts表中。我该怎么做?大致情况: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 2 个回复 最合适的回答,由SO网友:Michael Rogers 整理而成 总结一个工作示例@Parthavi Patel 答复这是一个页面模板。页面加载时,将执行代码。如果帖子太多,最好在上使用保守值posts_per_page 并调整offset 每个批次执行后的参数。 <?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(); ?> 参考/来源/学分:https://support.advancedcustomfields.com/forums/topic/migrate-a-custom-field-content-to-the_content/ SO网友:Parthavi Patel 首先从中获取数据wp_postmeta 桌子$description = get_post_meta( $post->ID, \'description\', true ); 尝试以下代码来更新内容$my_post = array( \'ID\' => $post->ID, \'post_content\' => $description, ); //Update the post into the database wp_update_post( $my_post ); 文章导航