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 built several Wordpress websites and noticed that custom fields are not restored to previous revisions. This might cause a problem when using custom fields to store content. Anybody knows how to add the custom fields to the revision history? Thanks

share|improve this question
add comment

1 Answer

Post revisions are for the fields in the posts database table and not the postmeta database table.

So if you want to create your own postmeta revision you could save the meta when the revision is made using _wp_put_post_revision and you can restore the meta using wp_restore_post_revision.

share|improve this answer
    
Doesn't _wp_put_post_revision save only post data (title, content)? It uses _wp_post_revision_fields which doesn't check for custom fields? My goal is to be able to restore the custom fields to any point in the history of the post, as in the revisions of the title and content. –  Tomer Lavi Jun 29 '11 at 14:53
    
@Tomer, that is exactly what i'm saying _wp_put_post_revision saves only post fields and not post meta (custom fields), so to save your custom fields before a post revision is created you can hook to the _wp_put_post_revision hook and save your the custom fields you want, and when you restore a revision you can use wp_restore_post_revision to restore those saved fields as well –  Bainternet Jun 29 '11 at 18:19
    
I see now, thanks. –  Tomer Lavi Jun 29 '11 at 18:37
add comment

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.