Skip to content

Instantly share code, notes, and snippets.

@ryelle
Last active December 4, 2020 23:29
Show Gist options
  • Save ryelle/52604f1a01de755586a8c73dd78b01b3 to your computer and use it in GitHub Desktop.
Save ryelle/52604f1a01de755586a8c73dd78b01b3 to your computer and use it in GitHub Desktop.
Demo block to test an entity records request with a `_fields` subset
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