wp_restore_post_revision_meta()WP 6.4.0

Restore the revisioned meta values for a post.

No Hooks.

Return

null. Nothing (null).

Usage

wp_restore_post_revision_meta( $post_id, $revision_id );
$post_id(int) (required)
The ID of the post to restore the meta to.
$revision_id(int) (required)
The ID of the revision to restore the meta from.

Changelog

Since 6.4.0 Introduced.

wp_restore_post_revision_meta() code WP 6.6.2

function wp_restore_post_revision_meta( $post_id, $revision_id ) {
	$post_type = get_post_type( $post_id );
	if ( ! $post_type ) {
		return;
	}

	// Restore revisioned meta fields.
	foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) {

		// Clear any existing meta.
		delete_post_meta( $post_id, $meta_key );

		_wp_copy_post_meta( $revision_id, $post_id, $meta_key );
	}
}