gpt4 book ai didi

wordpress-gutenberg - Wordpress Gutenberg withSelect 获取文章类型列表

转载 作者:行者123 更新时间:2023-12-04 02:54:59 29 4
gpt4 key购买 nike

我正在使用 Gutenberg 的 withSelect 包来尝试获取属于该站点的所有帖子类型。这是我的代码:

export default withSelect( select => {
// shorthand
const { getEntityRecords } = select( 'core' );

return {
typesList: getEntityRecords( 'types', '' ),
};
} )( SearchEdit );

但我没有得到任何返回。我还发现 withSelect 的文档非常稀疏,所以如果有人有任何进一步的信息会很好,我会尝试更新文档。

最佳答案

知道自从被问到这个问题已经有一段时间了,但我今天提出了这个问题,所以这里是一个答案。有一个方法叫getPostTypes() ,看下面的例子:

export default withSelect( select => {
const {getPostTypes} = select('core);

return {
typesList: getPostTypes(),
}
} )( YourEdit );

注: getPostTypes()将返回一个帖子类型对象的数组。如果您只需要名称,则需要将结果处理为所需的格式。

关于wordpress-gutenberg - Wordpress Gutenberg withSelect 获取文章类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53404030/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com