ACF\AI\Abilities
Taxonomy::get_rest_item_input_schema
Get REST input schema for taxonomy terms.
Method of the class: Taxonomy{}
No Hooks.
Returns
array.
Usage
// private - for code of main (parent) class only $result = $this->get_rest_item_input_schema( $acf_fields, $taxonomy_label, $hierarchical, $action ): array;
- $acf_fields(array) (required)
- ACF fields for this taxonomy.
- $taxonomy_label(string) (required)
- Taxonomy label for descriptions.
- $hierarchical(true|false)
- Whether taxonomy is hierarchical.
Default:false - $action(string)
- Action type ('create' or 'update').
Default:'create'
Changelog
| Since 6.8.0 | Introduced. |
Taxonomy::get_rest_item_input_schema() Taxonomy::get rest item input schema code ACF 6.8.8
private function get_rest_item_input_schema( array $acf_fields, string $taxonomy_label, bool $hierarchical = false, string $action = 'create' ): array {
$schema = array(
'type' => 'object',
'properties' => array(),
);
if ( 'update' === $action ) {
$schema['properties']['id'] = array(
'type' => 'integer',
'description' => sprintf( 'The ID of the %s term to update.', strtolower( $taxonomy_label ) ),
'required' => true,
);
}
$schema['properties']['name'] = array(
'type' => 'string',
'description' => sprintf( 'The name of the %s term.', strtolower( $taxonomy_label ) ),
'required' => 'update' !== $action,
);
$schema['properties']['description'] = array(
'type' => 'string',
'description' => sprintf( 'The description of the %s term.', strtolower( $taxonomy_label ) ),
'required' => false,
);
$schema['properties']['slug'] = array(
'type' => 'string',
'description' => sprintf( 'The slug of the %s term (auto-generated from name if not provided).', strtolower( $taxonomy_label ) ),
'required' => false,
);
if ( $hierarchical ) {
$schema['properties']['parent'] = array(
'type' => 'integer',
'description' => 'Parent term ID for hierarchical taxonomies. Use 0 or omit for top-level terms. For child terms, provide the ID of the parent term.',
'required' => false,
'default' => 0,
);
}
return $this->add_acf_fields_to_schema( $schema, $acf_fields );
}