이미 필드를 wp_posts 테이블에 수동으로 추가 한 경우에는 몇 개의 후크를 사용하여 게시물 페이지에 필드를 추가 한 다음 저장해야합니다.
// Function to register the meta box
function add_meta_boxes_callback($post_type, $post) {
add_meta_box('my_field', 'My Field', 'output_my_meta_box', 'post');
}
add_action('add_meta_boxes', 'add_meta_boxes_callback', 10, 2);
// Function to actually output the meta box
function output_my_meta_box($post) {
echo '<input type="text" name="my_field" value="' . $post->my_field . '" />';
}
// Function to save the field to the DB
function wp_insert_post_data_filter($data, $postarr) {
$data['my_field'] = $_POST['my_field'];
return $data;
}
add_filter('wp_insert_post_data', 'wp_insert_post_data_filter', 10, 2);
wp_insert_post_data_filter 함수는 $ data 배열을 반환해야합니다. (버전 4.1.1에서 테스트 됨) – mimarcel