Keep Custom Field Changes in Revisions
Saves chosen custom fields, such as a subtitle, price or event date, with every revision so restoring an older version brings those values back too.
Opens WPIDE on
Code
// Custom field keys to store with revisions.
$wpide_revision_meta_keys = array( 'subtitle', 'price', 'event_date' );
add_filter( 'wp_post_revision_meta_keys', function ( $keys ) use ( $wpide_revision_meta_keys ) {
return array_values( array_unique( array_merge( $keys, $wpide_revision_meta_keys ) ) );
} );
Notes
Needs WordPress 6.4 or newer; list the field keys in $wpide_revision_meta_keys.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.