我可以看到您在上面的代码中犯了几个错误,因此我冒昧地为您修复了它,并告诉我它是否解决了您的问题。您的问题有点含糊,但可以看到您的代码应该可以通过以下修复。
我用双正斜杠注释,其中的值被更改、添加或删除。
add_action( \'add_meta_boxes\', \'event_detail_box\' );
function event_detail_box() {
add_meta_box(
\'event_detail_box\',
__( \'Event Detail\', \'myplugin_textdomain\' ),
\'event_detail_box_content\',
\'event\',
\'normal\',
\'high\'
);
}
function event_detail_box_content( $post ) {
// No need to globalise a post that is an argument on this callback
$meta_p = get_post_meta($post->ID, "events_price", true);
$meta_l = get_post_meta($post->ID, "events_location", true);
echo \'<input type="hidden" name="events-nonce" id="events-nonce" value="\' . wp_create_nonce( \'events-nonce\' ) . \'" />\';
?>
<div class="tf-meta">
<ul>
<li><label>Event Price</label><input name="events_price" value="<?php echo $meta_p; ?>" /></li>
<li><label>Event Location</label><input name="events_location" size="50" value="<?php echo $meta_l; ?>" /></li>
</ul>
</div>
<?php
}
add_action (\'save_post\', \'save_events\');
// The save_post hook provides the post id to the return function
function save_events( $post_id ){
if ( !wp_verify_nonce( $_POST[\'events-nonce\'], \'events-nonce\' )) {
return $post_id;
}
if ( !current_user_can( \'edit_post\', $post_id ))
return $post_id;
update_post_meta($post_id, "events_price", $POST[\'events_price\'] );
update_post_meta($post_id, "events_location", $POST[\'events_location\'] );
}