I would like to have a multi select field for my categories. How can i do that?
My code doesn't work:
function getCategories () {
var options = [];
var categories = wp.data.select('core').getEntityRecords('taxonomy', 'category');
categories.forEach((category) => {
options.push({ value: category.id, label: category.name });
});
}
<SelectControl
multiple
label={__('Select a Post')}
help={__('Select a post to display as a banner.')}
options={getCategories}
/>
I would like to have a multi select field for my categories. How can i do that?
My code doesn't work:
function getCategories () {
var options = [];
var categories = wp.data.select('core').getEntityRecords('taxonomy', 'category');
categories.forEach((category) => {
options.push({ value: category.id, label: category.name });
});
}
<SelectControl
multiple
label={__('Select a Post')}
help={__('Select a post to display as a banner.')}
options={getCategories}
/>
Share
Improve this question
edited Jul 28, 2020 at 13:43
Tom J Nowell♦
61k7 gold badges79 silver badges148 bronze badges
asked Jul 28, 2020 at 12:54
180690180690
1812 silver badges9 bronze badges
1
|
1 Answer
Reset to default 0Ich have to write
options={getCategories()}
that solved this problem.
SelectControl
, and the component references choosing posts not categories. Use the edit link under the tags to answer as many of those questions as possible. How are you intending to save the values? – Tom J Nowell ♦ Commented Jul 28, 2020 at 13:30