Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have some code that updates a meta-key's value by incrementing...

    $post_id = $wpdb->get_var( $query );
    $meta = get_post_meta( $post_id, 'stuff', TRUE );
    $meta++;
    update_post_meta( $post_id, 'stuff', $meta );

I want to create and save a revision of the meta key/ value each time it is updated, so I can determine how many updates took place last week, last month, last year, etc.

I am looking at this code here, but I don't want to do it from the edit post screen, it needs to happen when I update the post meta.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You'd need to set up an additional custom field and update it whenever the user changes or updates the original custom field.

share|improve this answer
    
The problem with this is that I can only save history 1-update deep. I think I need to somehow use revisions. See my updated question –  marctain Jul 18 '12 at 16:18
    
You could use a serialized array instead of a straight string, and push the new revision time onto the serialized array. –  Aaron Holbrook Jul 18 '12 at 16:50
    
I'm not familiar with serialized arrays.. There could feasibly be around 200 custom fields per custom post (the fields are created dynamically), would I be saving an extra custom field for each of those? Would this serialized array be able to record each and everytime a meta value is updated? –  marctain Jul 18 '12 at 19:27
    
Yea - ok, so serialized arrays were a big stumper for me as well until I understood them. Basically a serialized array is a multidimensional array (think rows and columns) squashed flat so it fits into a one dimensional cell in a table. Read Nacin's post to understand a little more: nacin.com/2010/04/18/wordpress-serializing-data Yes the serialized array could expand as much as you need it to to store each revision (if you wanted you could even cap it at say 1000 or whatever you wished). You could either store each custom field in a separate history array or in one big giant one. –  Aaron Holbrook Jul 19 '12 at 12:19

Your Answer

 
discard

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.