3

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?

2

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.

| 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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