acf_get_metadata()ACF 5.2.3

Retrieves specific metadata from the database.

Хуки из функции

Возвращает

Разное.

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

acf_get_metadata( $post_id, $name, $hidden );
$post_id(int|строка)
The post id.
$name(строка)
The meta name.
По умолчанию: ''
$hidden(true|false)
If the meta is hidden (starts with an underscore).
По умолчанию: false

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

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

Код acf_get_metadata() ACF 6.0.4

function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
	// Allow filter to short-circuit logic.
	$null = apply_filters( 'acf/pre_load_metadata', null, $post_id, $name, $hidden );
	if ( $null !== null ) {
		return ( $null === '__return_null' ) ? null : $null;
	}

	// Decode $post_id for $type and $id.
	$decoded = acf_decode_post_id( $post_id );
	$id      = $decoded['id'];
	$type    = $decoded['type'];

	// Hidden meta uses an underscore prefix.
	$prefix = $hidden ? '_' : '';

	// Bail early if no $id (possible during new acf_form).
	if ( ! $id ) {
		return null;
	}

	// Determine CRUD function.
	// - Relies on decoded post_id result to identify option or meta types.
	// - Uses xxx_metadata(type) instead of xxx_type_meta() to bypass additional logic that could alter the ID.
	if ( $type === 'option' ) {
		return get_option( "{$prefix}{$id}_{$name}", null );
	} else {
		$meta = get_metadata( $type, $id, "{$prefix}{$name}", false );
		return isset( $meta[0] ) ? $meta[0] : null;
	}
}