why shouldn’t i save metadata when its a revision


I’m reading a book about WordPress and I’m new and confused.

Why does the author always not save data in the metadata box when its a revision. just in case its not clear, what i refer to by metadata box is the one added by 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’]));
Jiew Meng 5 months 0 Answers 36 views 0

Leave an answer