acf_field_gallery::format_value
This filter is appied to the $value after it is loaded from the db and before it is returned to the template
Метод класса: acf_field_gallery{}
Хуков нет.
Возвращает
$value. (mixed) the modified value
Использование
$acf_field_gallery = new acf_field_gallery(); $acf_field_gallery->format_value( $value, $post_id, $field );
- $value(обязательный)
- .
- $post_id(обязательный)
- .
- $field(обязательный)
- .
Список изменений
| С версии 3.6 | Введена. |
Код acf_field_gallery::format_value() acf field gallery::format value ACF 6.4.2
function format_value( $value, $post_id, $field ) {
// Bail early if no value.
if ( ! $value ) {
return false;
}
// Clean value into an array of IDs.
$attachment_ids = array_map( 'intval', acf_array( $value ) );
// Find posts in database (ensures all results are real).
$posts = acf_get_posts(
array(
'post_type' => 'attachment',
'post__in' => $attachment_ids,
'update_post_meta_cache' => true,
'update_post_term_cache' => false,
)
);
// Bail early if no posts found.
if ( ! $posts ) {
return false;
}
// Format values using field settings.
$value = array();
foreach ( $posts as $post ) {
// Return object.
if ( $field['return_format'] == 'object' ) {
$item = $post;
// Return array.
} elseif ( $field['return_format'] == 'array' ) {
$item = acf_get_attachment( $post );
// Return URL.
} elseif ( $field['return_format'] == 'url' ) {
$item = wp_get_attachment_url( $post->ID );
// Return ID.
} else {
$item = $post->ID;
}
// Append item.
$value[] = $item;
}
// Return.
return $value;
}