WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

reading a book about wordpress ... sorry if i ask the too many questions at 1 go but i am 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’]));
share|improve this question
up vote 2 down vote accepted

You omitted how is this function called. I assume it is added to save_post action.

This action passes current post id as argument. In case of revision that would be revision id and not parent post id. So, as I see it, there is no reason to save additional data for revision (creating duplicate set of it).


Scratch that.

I looked through source code. Apparently *_post_meta functions will automatically change to parent post id if passed revision post id. So you might modify original post, thinking you are modifying revision.

share|improve this answer
yes its save_post, i see the point. are revisions like copies of the post data every time i save the post, so that it becomes something like a wiki? if so, i guess it stores a duplicate of the row, wont that bloat the database very fast? – Jiew Meng Sep 11 '10 at 14:46
@jiewmeng: Revisions are indeed historical copies of your post. They are used to store previous versions if you edit an already saved post, but also for autosaves while you are editing. – Jan Fabry Sep 11 '10 at 14:50
Yes, revisions can bloat database. There is a constant that controls if (or how many) revisions should be stored per post (not counting one for auto-save) See codex.wordpress.org/Revision_Management – Rarst Sep 11 '10 at 15:02

When I look at my postmeta table, it appears no metadata is ever saved for post revisions. I don't think it has to be this way: I can think of some use cases where it would be useful for plugins to save additional metadata for revisions too. Take your example, probably from a webshop example: if I first create a product with a price of $20, then later reduce the price to $10, this will probably save the old text fields as a revision, but it will erase the old price fields. It could be useful to save a history of the prices too.

I assume the functions that deal with metadata don't fully support working with revisions of metadata, so we should not expect much support from plugins yet. But, if you create a plugin, keep in mind how saving (and retrieving) historical metadata could be useful.

share|improve this answer
Fields to be saved in revision are determined in _wp_post_revision_fields() and can be filtered, so additional data can be versioned. But it indeed seems to lack support for working with meta functions (see update above - they simply ignore revisions and bump up to original post). – Rarst Sep 11 '10 at 15:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.