它在管理編輯畫面呈現之前,您可以過濾內容。
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'
}
要運行此腳本,你可以簡單地創建一個暫新的頁面,然後創建一個特定的模板文件,該頁面,並把上面的代碼到該文件(然後訪問該頁面)。