acf_update_metaref()ACF 5.2.3

acf_update_metaref

Updates reference metadata in the database.

No Hooks.

Returns

(Int|true|false). Meta ID if the key didn't exist, true on successful update, false on failure.

Usage

acf_update_metaref( $post_id, $type, $references );
$post_id((int|string))
The post id.
$type
.
Default: 'fields'
$references(array)
An array of references.
Default: array()

Changelog

Since 5.2.3 Introduced.

acf_update_metaref() code ACF 6.0.4

function acf_update_metaref( $post_id = 0, $type = 'fields', $references = array() ) {

	// Get current references.
	$current = acf_get_metaref( $post_id, $type );

	// Merge in new references.
	$references = array_merge( $current, $references );

	// Simplify groups
	if ( $type === 'groups' ) {
		$references = array_values( $references );
	}

	// Remove duplicate references.
	$references = array_unique( $references );

	// Update metadata.
	return acf_update_metadata( $post_id, "_acf_$type", $references );
}