acf_get_metadata_by_field()
Gets metadata from the database.
Хуки из функции
Возвращает
Разное.
Использование
acf_get_metadata_by_field( $post_id, $field, $hidden );
- $post_id(int|строка)
- The post id.
- $field(массив)
- The field array.
По умолчанию:array() - $hidden(true|false)
- True if we should return the reference key.
По умолчанию:false
Список изменений
| С версии 6.4 | Введена. |
Код acf_get_metadata_by_field() acf get metadata by field ACF 6.4.2
function acf_get_metadata_by_field( $post_id = 0, $field = array(), bool $hidden = false ) {
if ( empty( $field['name'] ) ) {
return null;
}
// Allow filter to short-circuit logic.
$null = apply_filters( 'acf/pre_load_metadata', null, $post_id, $field['name'], $hidden );
if ( $null !== null ) {
return ( $null === '__return_null' ) ? null : $null;
}
// Decode the $post_id for $type and $id.
$decoded = acf_decode_post_id( $post_id );
$id = $decoded['id'];
$type = $decoded['type'];
// Bail early if no $id (possible during new acf_form).
if ( ! $id ) {
return null;
}
$meta_instance = acf_get_meta_instance( $type );
if ( ! $meta_instance ) {
return false;
}
if ( $hidden ) {
return $meta_instance->get_reference( $id, $field['name'] );
}
return $meta_instance->get_value( $id, $field );
}