admin管理员组文章数量:1327843
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.
本文标签: block editorCategories in Gutenberg
版权声明:本文标题:block editor - Categories in Gutenberg 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742219540a2435193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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