我最近才开始工作。您应该搜索并替换metaname
使用您的元框名称。
保持格式的关键是使用wpautop();
保存数据时。
add_action( \'add_meta_boxes\', \'add_metaname_box\');
add_action( \'save_post\', \'metaname_save\');
function add_metaname_box() {
add_meta_box(
\'metaname_id\',
__( \'metaname text\', \'metaname_textdomain\'),
\'metaname_custom_box\',
\'page\'
);
}
function metaname_custom_box() {
global $post;
wp_nonce_field( plugin_basename( __FILE__ ), \'metaname_noncename\' );
$data = get_post_meta($post->ID, \'metaname_custom_box\', true);
echo <<<EOT
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#metaname_custom_box").addClass("mceEditor");
if ( typeof( tinyMCE ) == "object" &&
typeof( tinyMCE.execCommand ) == "function" ) {
tinyMCE.execCommand("mceAddControl", false, "metaname_custom_box");
}
});
</script>
<textarea id="metaname_custom_box" name="metaname_custom_box">$data</textarea>
EOT;
}
function metaname_save($post_id) {
global $post;
// Verify
if ( !wp_verify_nonce( $_POST[\'metaname_noncename\'], plugin_basename(__FILE__) )) {
return $post_id;
}
if ( \'page\' == $_POST[\'post_type\'] ) {
if ( !current_user_can( \'edit_page\', $post_id ))
return $post_id;
} else {
if ( !current_user_can( \'edit_post\', $post_id ))
return $post_id;
}
$key = \'metaname_custom_box\';
$data = wpautop($_POST[$key]);
// New, Update, and Delete
if(get_post_meta($post_id, $key) == "")
add_post_meta($post_id, $key, $data, true);
elseif($data != get_post_meta($post_id, $key, true))
update_post_meta($post_id, $key, $data);
elseif($data == "")
delete_post_meta($post_id, $key, get_post_meta($post_id, $key, true));
}