acf_field_gallery::format_value_for_jsonld
Formats the field value for JSON-LD output.
Метод класса: acf_field_gallery{}
Хуков нет.
Возвращает
mixed.
Использование
$acf_field_gallery = new acf_field_gallery(); $acf_field_gallery->format_value_for_jsonld( $value, $post_id, $field );
- $value(разное) (обязательный)
- The value of the field.
- $post_id(int|строка) (обязательный)
- The ID of the post.
- $field(массив) (обязательный)
- The field array.
Список изменений
| С версии 6.8.0 | Введена. |
Код acf_field_gallery::format_value_for_jsonld() acf field gallery::format value for jsonld ACF 6.8.8
public function format_value_for_jsonld( $value, $post_id, $field ) {
if ( empty( $value ) || ! is_array( $value ) ) {
return null;
}
$image_field_type = acf_get_field_type( 'image' );
$images = array();
foreach ( $value as $attachment_id ) {
// Create a temporary field config with the same output format.
$image_field = array(
'schema_output_format' => $field['schema_output_format'] ?? '',
'schema_property' => $field['schema_property'] ?? '',
);
$formatted = $image_field_type->format_value_for_jsonld( $attachment_id, $post_id, $image_field );
if ( $formatted ) {
$images[] = $formatted;
}
}
return empty( $images ) ? null : $images;
}