您可以在内容显示在管理员编辑屏幕之前对其进行过滤。
function my_filter_function_name( $content, $post_id ) {
if(get_post_type($post_id) == 'the_post_type_in_question'){
$serialized_content = $content;
$content_array = unserialize($serialized_content);
// do something with this array to put it in the format you want
// .....
$content = $new_formatted_content;
}
return $content;
}
add_filter( 'content_edit_pre', 'my_filter_function_name', 10, 2 );
但是,这似乎对你没有多大用处。
在您的情况下,我建议您花时间编写一个脚本来转换所有这些帖子,以便将所有内容存储为post meta。 (首先创建自定义字段)。
如果您的主题不是基于任何框架构建的,那么我认为创建自定义字段的最快方法是使用Advanced Custom Fields plugin。
然后,一旦您知道meta_keys,您就可以编写该脚本。例如
$posts = get_posts('post_type'=>'the_post_type','posts_per_page'=> -1);
foreach($posts as $post){
$content_array = unserialize($post->post_content);
// how you do the next bit will depend on whether or not this is an associative array. I'm going to assume it is (because it's a little easier :) )
foreach($content_array as $meta_key=>$meta_value){
update_post_meta($post->ID, $meta_key, $meta_value);
}
// just put what you actually want as the post content back into the post content:
wp_update_post(array('ID'=>$post->ID,'post_content'=>$content_array['post_content'])); // assuming the key of the element you want to be the post content is 'post_content'
}
要运行此脚本,您可以简单地创建一个临时的新页面,然后专门为该页面创建一个模板文件,并将上述代码放入该文件(然后访问该页面)。