-
Notifications
You must be signed in to change notification settings - Fork 1
What can I use with getEntityRecords?
The selectData
field type of this library uses getEntityRecords
that requires 2 arguments: kind
and entity
.
And the selectData field of this library requires a third one: value
(value to display in the select component).
List of kinds can be found here or summarized below.
and we can therefore understand that the kinds/Entities available are:
1 console command to find the entities for a kind (replace postType with your kind):
const entitiesConfig = wp.data.select( 'core' ).getEntitiesConfig('postType')
Kind | Entity | Value (label) | Other values available with a command line |
---|---|---|---|
postType | post | title.rendered | const posts = wp.data.select('core').getEntityRecords('postType', 'post') |
postType | page | title.rendered | const pages = wp.data.select('core').getEntityRecords('postType', 'page') |
postType | attachment | title.rendered | const attachments = wp.data.select('core').getEntityRecords('postType', 'attachment') |
postType | nav_menu_item | title.rendered | const nav_menu_items = wp.data.select('core').getEntityRecords('postType', 'nav_menu_item') |
postType | wp_block | - | const wp_blocks = wp.data.select('core').getEntityRecords('postType', 'wp_block') |
postType | wp_template | title.rendered | const wp_templates = wp.data.select('core').getEntityRecords('postType', 'wp_template') |
postType | wp_template_part | title.rendered | const wp_template_parts = wp.data.select('core').getEntityRecords('postType', 'wp_template_part') |
postType | wp_navigation | title.rendered | const wp_navigations = wp.data.select('core').getEntityRecords('postType', 'wp_navigation') |
taxonomy | category | name | const categories = wp.data.select('core').getEntityRecords('taxonomy', 'category') |
taxonomy | post_tag | title.rendered | const post_tags = wp.data.select('core').getEntityRecords('taxonomy', 'post_tag') |
taxonomy | nav_menu | name | const nav_menus = wp.data.select('core').getEntityRecords('taxonomy', 'nav_menu') |
root | media | title.rendered | const medias = wp.data.select('core').getEntityRecords('root', 'media') |
root | site | title | const sites = wp.data.select('core').getEntityRecords('root', 'site') |
root | postType | - | const postTypes = wp.data.select('core').getEntityRecords('root', 'postType') |
root | taxonomy | - | const taxonomies = wp.data.select('core').getEntityRecords('root', 'taxonomy') |
root | sidebar | name | const sidebars = wp.data.select('core').getEntityRecords('root', 'sidebar') |
root | widget | - | const widgets = wp.data.select('core').getEntityRecords('root', 'widget') |
root | widgetType | - | const widgetTypes = wp.data.select('core').getEntityRecords('root', 'widgetType') |
root | user | username | const users = wp.data.select('core').getEntityRecords('root', 'user') |
root | comment | - | const comments = wp.data.select('core').getEntityRecords('root', 'comment') |
root | menu | name | const menus = wp.data.select('core').getEntityRecords('root', 'menu') |
root | menuItem | title.rendered | const menuItems = wp.data.select('core').getEntityRecords('root', 'menuItem') |
root | menuLocation | name | const menuLocations = wp.data.select('core').getEntityRecords('root', 'menuLocation') |
root | globalStyles | - | const globalStyles = wp.data.select('core').getEntityRecords('root', 'globalStyles') |
root | plugin | - | const plugins = wp.data.select('core').getEntityRecords('postType', 'plugin') |
root | theme | - | const themes = wp.data.select('core').getEntityRecords('postType', 'theme') |
To see the other values, I find it easier to use getEntityRecords command in the console and then look at the preview of the fetch request result in the inspector.
The Label column is left blank when the available data is too complex to prefer one, or when I had no data to work with.
Don't forget that getEntityRecords
accepts an EntityQuery
argument, which allows to query everything:
Example stolen on Misha Rudrastyh blog:
const query = {
per_page : 10, // set -1 to display ALL
exclude : 50, // or pass multiple values in an array, e.g. [ 1, 9098 ]
parent_exclude : 43, // or [ 43, 44, 98 ]
orderby : 'date',
order : 'asc',
status : 'publish', // or [ 'publish', 'draft', 'future' ]
categories : [ 5, 10, 15 ], // category ID or IDs
tags : 4, // tag ID, you can pass multiple too [ 4, 7 ]
search : 'search query',
}
const posts = select( 'core' ).getEntityRecords( 'postType', 'post', query );