我正在使用带有自定义元字段的自定义帖子类型,但这些自定义元字段似乎不会触发自动保存和“未保存的更改”对话框。对我来说,自动保存不如“未保存的更改”对话框重要-有没有办法触发它?
function add_meta_boxes() {
add_meta_box(\'places_location\', __(\'Location\'), array(&$this, \'location_box\'), \'place\', \'normal\', \'high\');
}
function location_box($post) {
wp_nonce_field(plugin_basename(__FILE__), \'places_location_nonce\');
$lat = get_post_meta($post->ID, \'places_lat\', true);
$lng = get_post_meta($post->ID, \'places_lng\', true);
?>
<p>
<label>
Latitude:
<input name="places_lat" value="<?php echo esc_attr($lat); ?>" />
</label>
<label>
Longitude:
<input name="places_lng" value="<?php echo esc_attr($lng); ?>" />
</label>
</p>
<?php
}
function save_place($id) {
// skip unverified location nonces
if(!wp_verify_nonce($_POST[\'places_location_nonce\'], plugin_basename(__FILE__))) return;
// skip autosave calls
// commenting this out still doesn\'t trigger saving these fields on autosave
//if(defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) return;
// update our custom post meta
update_post_meta($id, \'places_lat\', (float)$_POST[\'places_lat\']);
update_post_meta($id, \'places_lng\', (float)$_POST[\'places_lng\']);
}