我正在读一本关于WordPress的书,我是新来的,很困惑。
为什么作者在修订时总是不将数据保存在元数据框中。以防万一,我所指的“按元数据”框是由add_meta_box
.
//save meta box data
function pp_save_meta_box($post_id,$post) {
// if post is a revision skip saving our meta box data
if($post->post_type == \'revision\') { return; }
// process form data if $_POST is set
if(isset($_POST[’pp_sku’]) && $_POST[’pp_sku’] != ‘’) {
// save the meta box data as post meta using the post ID as a unique prefix
update_post_meta($post_id,’pp_sku’, esc_attr($_POST[’pp_sku’]));
update_post_meta($post_id,’pp_price’, esc_attr($_POST[’pp_price’]));
update_post_meta($post_id,’pp_weight’, esc_attr($_POST[’pp_weight’]));
update_post_meta($post_id,’pp_color’, esc_attr($_POST[’pp_color’]));
update_post_meta($post_id,’pp_inventory’,esc_attr($_POST[’pp_inventory’]));
}
}