ACF\AI\GEO
GEO::process_fields
Process ACF fields and map them to Schema.org structure
Takes an array of field objects and processes them based on their schema_property setting. Fields with a schema_property are mapped to core Schema.org properties. Properties that expect objects (like 'author' or 'publisher') automatically get proper "@type" added. Fields without a schema_property are skipped.
Method of the class: GEO{}
No Hooks.
Returns
Array. Processed data with core properties, with 'field_types' key containing types from qualified properties.
Usage
$result = GEO::process_fields( $field_objects );
- $field_objects(array) (required)
- Array of ACF field objects with values.
Changelog
| Since 6.8.0 | Introduced. |
GEO::process_fields() GEO::process fields code ACF 6.8.8
public static function process_fields( $field_objects ) {
$data = array();
$field_types = array();
foreach ( $field_objects as $field_name => $field_object ) {
// Skip empty values.
if ( null === $field_object['value'] || '' === $field_object['value'] ) {
continue;
}
// Check if this field has a schema property mapping.
$schema_property = $field_object['schema_property'] ?? '';
if ( ! empty( $schema_property ) ) {
// Parse qualified property (e.g., "Offer.price" -> type: "Offer", property: "price").
$parsed = Schema::parse_qualified_property( $schema_property );
$property_name = $parsed['property'];
// Collect field types from qualified properties.
if ( $parsed['type'] ) {
$field_types[] = $parsed['type'];
}
$formatted_value = self::format_field_value_for_jsonld( $field_object['value'], $field_object );
// Field has a schema property - map to core property using just the property name.
$data[ $property_name ] = $formatted_value;
}
}
// Add @type to nested objects based on schema.org ranges.
$data = self::add_types_to_nested_objects( $data );
// Include field types from qualified properties.
if ( ! empty( $field_types ) ) {
$data['field_types'] = array_values( array_unique( $field_types ) );
}
return $data;
}