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.

Method of the class: acf_field_date_picker{}

No Hooks.

Returns

string|null. ISO 8601 formatted date or null.

Usage

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

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' );
}