是否可以使用 Gutenberg getEntityRecords()
获取所有产品类别?
我找到了一个获取帖子类别的代码如下
var query = {per_page: 100}
categoriesList = getEntityRecords( 'taxonomy', 'category', query );
我可以更改上面的代码以获取所有 woocommerce 产品类别吗?
最佳答案
我也搜索过同样的东西。但最后我决定使用 apiFetch 来完成这项任务(遵循 woocommerce-gutenberg-products-block 插件)。
例如一个示例用例:
const apiFetch = wp.apiFetch;
const { addQueryArgs } = wp.url;
const productCategories = (queryArgs) => {
return apiFetch({
path: addQueryArgs(`wc/store/products/categories`, {
per_page: 0,
...queryArgs,
}),
});
};
productCategories().then((categories) => {
console.log(categories);
});
关于javascript - 使用 Gutenberg getEntityRecords 获取 woocommerce 产品类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54900536/