我不明白为什么这些函数在保存startdate和starttime时不保存价格和位置数据。当我打印($custom)时,我可以看到[events\\u price]=>数组([0]=>)为空。。
function event_detail_box_content( $post ) {
$custom = get_post_custom($post->ID);
$meta_sd = $custom["events_startdate"][0];
$meta_pr = $custom["events_price"][0];
$meta_lo = $custom["events_location"][0];
$meta_st = $meta_sd;
$time_format = get_option(\'time_format\');
if ($meta_sd == null) { $meta_sd = time(); $meta_st = 0;}
$clean_sd = date("D, M d, Y", $meta_sd);
$clean_st = date($time_format, $meta_st);
echo \'<input type="hidden" name="events-nonce" id="events-nonce" value="\' . wp_create_nonce( \'events-nonce\' ) . \'" />\';
?>
<div class="tf-meta">
<ul>
<li><label>Event Date</label><input name="events_startdate" class="tfdate" value="<?php echo $clean_sd; ?>" /></li>
<li><label>Event Time</label><input name="events_starttime" value="<?php echo $clean_st; ?>" /><em>Use 24h format (7pm = 19:00)</em></li>
<li><label>Event Price</label><input name="events_price" value="<?php echo $meta_pr; ?>" /></li>
<li><label>Event Location</label><input name="events_location" value="<?php echo $meta_lo; ?>" /></li>
</ul>
</div>
<?php
print_r($custom);
}
add_action (\'save_post\', \'save_events\');
function save_events($post_id){
if ( !wp_verify_nonce( $_POST[\'events-nonce\'], \'events-nonce\' )) { return; }
if ( !current_user_can( \'edit_post\')) return;
if(!isset($_POST["events_startdate"])): return; endif;
$updatestartd = strtotime ( $_POST["events_startdate"] . $_POST["events_starttime"] );
update_post_meta($post_id, "events_startdate", $updatestartd );
update_post_meta($post_id, "events_price", $POST["events_price"] );
update_post_meta($post_id, "events_location", $POST["events_location"] );
}