-
Notifications
You must be signed in to change notification settings - Fork 1
Select data field
Loïc Antignac edited this page May 24, 2022
·
12 revisions
The select data field is probably the most interesting since it allows to select entities of different kinds.
This field is based on the getEntityRecords function and by default, it only requests the following informations:
[
'slug' => 'select_pages',
'type' => 'selectData',
'args' => [
'is_multiple' => true,
'is_clearable' => true,
'data' => [
'kind' => 'postType',
'name' => 'page',
'value' => 'title.rendered',
],
],
'labels' => [
'label' => 'select_pages_label',
'help' => '',
],
],
is_multiple
parameter defines whether it is possible to select 1 or more elements.
is_clearable
parameter defines whether it is possible to clear the selection.
And the most important part:
data
defines 3 arguments:
-
kind
which defines the type of entity -
name
which defines the name of the entity -
value
which defines the value that we want to display in the select component
Since the component is based on getEntityRecords
which itself is based on the REST API, the values to fill in data can be found in the REST API documentation.
See this page to facilitate this work
Another very interesting argument can be added to data
: query
Example:
[
'slug' => 'main_category',
'type' => 'selectData',
'args' => [
'is_multiple' => false,
'is_clearable' => true,
'data' => [
'kind' => 'taxonomy',
'name' => 'category',
'value' => 'name',
'query' => [
'exclude' => 50,
'orderby' => 'date',
],
],
],
'labels' => [
'label' => 'main_category_label',
'help' => '',
],
],