acf_copy_metadata()ACF 5.3.8

acf_copy_postmeta

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

Хуков нет.

Возвращает

null. Ничего.

Использование

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.

Список изменений

С версии 5.3.8 Введена.

Код acf_copy_metadata() ACF 5.10.2

function acf_copy_metadata( $from_post_id = 0, $to_post_id = 0 ) {

	// Get all postmeta.
	$meta = acf_get_meta( $from_post_id );

	// Check meta.
	if ( $meta ) {

		// Slash data. WP expects all data to be slashed and will unslash it (fixes '\' character issues).
		$meta = wp_slash( $meta );

		// Loop over meta.
		foreach ( $meta as $name => $value ) {
			acf_update_metadata( $to_post_id, $name, $value );
		}
	}
}