フィールドを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