acf_field_date_picker::format_value_for_jsonld │ public │ ACF 6.8.0

Formats the field value for JSON-LD output.

Converts the stored Ymd format to ISO 8601 date format.

Метод класса: acf_field_date_picker{}

Хуков нет.

Возвращает

string|null. ISO 8601 formatted date or null.

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

$acf_field_date_picker = new acf_field_date_picker();
$acf_field_date_picker->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_date_picker::format_value_for_jsonld() ACF 6.8.11

public function format_value_for_jsonld( $value, $post_id, $field ) {
	if ( empty( $value ) || ! is_string( $value ) ) {
		return null;
	}

	// ACF stores date_picker internally as 'Ymd' (e.g., 20231225).
	$date = \DateTime::createFromFormat( 'Ymd', $value );
	if ( ! $date ) {
		return null;
	}

	// Return ISO 8601 date format (YYYY-MM-DD).
	return $date->format( 'Y-m-d' );
}