ACF\AI\Abilities
PostType::get_rest_item_output_schema
Gets the REST schema for item(s) in a CPT.
Method of the class: PostType{}
No Hooks.
Returns
array|null. Schema array or null if not available.
Usage
// private - for code of main (parent) class only $result = $this->get_rest_item_output_schema( $acf_fields, $post_type, $type );
- $acf_fields(array) (required)
- An array of ACF fields present on the post type.
- $post_type(string) (required)
- The post type to get the schema for.
- $type(string)
- Schema type:
'item'or'collection'.
Default:'item'
Changelog
| Since 6.8.0 | Introduced. |
PostType::get_rest_item_output_schema() PostType::get rest item output schema code ACF 6.8.8
private function get_rest_item_output_schema( array $acf_fields, string $post_type, string $type = 'item' ) {
$post_type_object = get_post_type_object( $post_type );
if ( ! $post_type_object ) {
return null;
}
$controller = $post_type_object->get_rest_controller();
if ( ! $controller || ! method_exists( $controller, 'get_public_item_schema' ) ) {
return null;
}
$schema = $controller->get_public_item_schema();
$schema = $this->add_acf_fields_to_schema( $schema, $acf_fields );
if ( $type === 'collection' ) {
return array(
'type' => 'array',
'items' => $schema,
);
}
return $schema;
}