acf_field_gallery::format_value_for_jsonldpublicACF 6.8.0

Formats the field value for JSON-LD output.

Method of the class: acf_field_gallery{}

No Hooks.

Returns

mixed.

Usage

$acf_field_gallery = new acf_field_gallery();
$acf_field_gallery->format_value_for_jsonld( $value, $post_id, $field );
$value(mixed) (required)
The value of the field.
$post_id(int|string) (required)
The ID of the post.
$field(array) (required)
The field array.

Changelog

Since 6.8.0 Introduced.

acf_field_gallery::format_value_for_jsonld() code 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;
}