Last active
December 4, 2020 23:29
-
-
Save ryelle/52604f1a01de755586a8c73dd78b01b3 to your computer and use it in GitHub Desktop.
Demo block to test an entity records request with a `_fields` subset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { registerBlockType } = wp.blocks; | |
const { createElement } = wp.element; | |
const { useSelect } = wp.data; | |
registerBlockType("ryelle/select-fields-test", { | |
title: "Fields Test", | |
category: "common", | |
icon: "flag", | |
edit: () => { | |
const data = useSelect((select) => | |
select("core").getEntityRecords("postType", "post", { | |
_fields: ["id", "slug", "title"], | |
}) | |
); | |
console.table(data); | |
return createElement( | |
"div", | |
{}, | |
"Field test. Open console to view select results." | |
); | |
}, | |
save: () => null, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment