acf_field_date_and_time_picker::format_value_for_jsonld
Formats the field value for JSON-LD output.
Converts the stored Y-m-d H:i:s format to ISO 8601 datetime format.
Метод класса: acf_field_date_and_time_picker{}
Хуков нет.
Возвращает
string|null. ISO 8601 formatted datetime or null.
Использование
$acf_field_date_and_time_picker = new acf_field_date_and_time_picker(); $acf_field_date_and_time_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_and_time_picker::format_value_for_jsonld() acf field date and time picker::format value for jsonld 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_time_picker internally as 'Y-m-d H:i:s'.
// Use WordPress site timezone so the ISO 8601 offset is correct.
$date = \DateTime::createFromFormat( 'Y-m-d H:i:s', $value, wp_timezone() );
if ( ! $date ) {
return null;
}
// Return ISO 8601 datetime format with timezone.
return $date->format( 'c' );
}