ACF\AI\GEO
FieldSettings::get_schema_properties
Get available Schema.org properties for a field type
Returns a hierarchical array of Schema.org properties organized by type, filtered to only include properties compatible with the field type.
Uses pre-computed compatibility data for fast lookups.
Method of the class: FieldSettings{}
Hooks from the method
Returns
Array. Array of properties grouped by Schema.org type.
Usage
$FieldSettings = new FieldSettings(); $FieldSettings->get_schema_properties( $field_type, $context_id ): array;
- $field_type(string)
- The ACF field type name.
Default:'' - $context_id(int)
- Optional field group ID for context-aware priority ordering.
Changelog
| Since 6.8.0 | Introduced. |
FieldSettings::get_schema_properties() FieldSettings::get schema properties code ACF 6.8.8
public function get_schema_properties( string $field_type = '', int $context_id = 0 ): array {
// Build cache key including context.
$cache_key = $field_type . '_' . $context_id;
// Return cached result if available.
if ( isset( self::$properties_cache[ $cache_key ] ) ) {
return self::$properties_cache[ $cache_key ];
}
$roles = array();
// Get compatible properties using pre-computed data.
$compatible_set = $this->get_compatible_properties_set( $field_type );
if ( empty( $compatible_set ) ) {
self::$properties_cache[ $cache_key ] = $roles;
return $roles;
}
// Get all properties grouped by type from schema.org vocabulary.
$properties_by_type = Schema::get_properties_by_type();
// Get priority types with context-aware ordering.
$priority_types = Schema::get_priority_types( $context_id );
// Add priority types first.
foreach ( $priority_types as $type ) {
if ( isset( $properties_by_type[ $type ] ) ) {
$type_compatible = array();
foreach ( $properties_by_type[ $type ] as $property ) {
if ( isset( $compatible_set[ $property ] ) ) {
$type_compatible[ $type . '.' . $property ] = $property;
}
}
if ( ! empty( $type_compatible ) ) {
$type_label = sprintf( '%s Properties', $type );
$roles[ $type_label ] = $type_compatible;
}
}
}
// Add remaining types alphabetically.
foreach ( $properties_by_type as $type => $properties ) {
// Skip priority types (already processed).
if ( in_array( $type, $priority_types, true ) ) {
continue;
}
// Skip types with no properties.
if ( empty( $properties ) ) {
continue;
}
$type_compatible = array();
foreach ( $properties as $property ) {
if ( isset( $compatible_set[ $property ] ) ) {
$type_compatible[ $type . '.' . $property ] = $property;
}
}
if ( ! empty( $type_compatible ) ) {
$type_label = sprintf( '%s Properties', $type );
$roles[ $type_label ] = $type_compatible;
}
}
/**
* Filter the available Schema.org properties.
*
* Allows developers to add custom Schema.org properties or modify existing ones.
*
* @param array $properties The Schema.org role mappings grouped by type.
* @param string $field_type The ACF field type being configured.
*/
$roles = apply_filters( 'acf/schema/schema_properties', $roles, $field_type );
// Cache the result.
self::$properties_cache[ $cache_key ] = $roles;
return $roles;
}