acf_copy_metadata()ACF 5.3.8

Copies meta from one post to another. Useful for saving and restoring revisions.

No Hooks.

Returns

null. Nothing (null).

Usage

acf_copy_metadata( $from_post_id, $to_post_id );
$from_post_id(int|string)
The post id to copy from.
$to_post_id(int|string)
The post id to paste to.

Changelog

Since 5.3.8 Introduced.

acf_copy_metadata() code ACF 6.8.8

function acf_copy_metadata( $from_post_id = 0, $to_post_id = 0 ) {
	// Get all metadata.
	$meta = acf_get_meta( $from_post_id );

	$decoded  = acf_decode_post_id( $to_post_id );
	$instance = acf_get_meta_instance( $decoded['type'] );

	if ( $meta && $instance ) {
		$instance->update_meta( $decoded['id'], $meta );
	}
}