acf_get_meta()ACF 5.8.0

acf_get_meta

Returns an array of "ACF only" meta for the given post_id.

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

Возвращает

Массив.

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

acf_get_meta( $post_id );
$post_id(разное)
The post_id for this data.

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

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

Код acf_get_meta() ACF 5.10.2

function acf_get_meta( $post_id = 0 ) {

	// Allow filter to short-circuit load_value logic.
	$null = apply_filters( 'acf/pre_load_meta', null, $post_id );
	if ( $null !== null ) {
		return ( $null === '__return_null' ) ? null : $null;
	}

	// Decode $post_id for $type and $id.
	extract( acf_decode_post_id( $post_id ) );

	// 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' ) {
		$allmeta = acf_get_option_meta( $id );
	} else {
		$allmeta = get_metadata( $type, $id, '' );
	}

	// Loop over meta and check that a reference exists for each value.
	$meta = array();
	if ( $allmeta ) {
		foreach ( $allmeta as $key => $value ) {

			// If a reference exists for this value, add it to the meta array.
			if ( isset( $allmeta[ "_$key" ] ) ) {
				$meta[ $key ]    = $allmeta[ $key ][0];
				$meta[ "_$key" ] = $allmeta[ "_$key" ][0];
			}
		}
	}

	// Unserialized results (get_metadata does not unserialize if $key is empty).
	$meta = array_map( 'maybe_unserialize', $meta );

	/**
	 * Filters the $meta array after it has been loaded.
	 *
	 * @date    25/1/19
	 * @since   5.7.11
	 *
	 * @param   array $meta The arary of loaded meta.
	 * @param   string $post_id The $post_id for this meta.
	 */
	return apply_filters( 'acf/load_meta', $meta, $post_id );
}