# WordPress Core Data
Namespace: `core`.
## Dynamically generated selectors
There are a number of user-friendly selectors that are wrappers of the more generic `getEntityRecord` and `getEntityRecords` that can be used to retrieve information for the various entities.
### getPostType
Returns the information for a given post type.
_Usage_
import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
const postType = useSelect(
( select ) => select( coreDataStore ).getPostType( 'post' )
// Equivalent to: select( coreDataStore ).getEntityRecord( 'root', 'postType', 'post' )
);
_Parameters_
- postType `string`
_Returns_
- `EntityRecord | undefined`: Record.
### getPostTypes
Returns the information for post types.
_Usage_
import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
const postTypes = useSelect( ( select ) => {
return select( coreDataStore ).getPostTypes( { per_page: 4 } );
// Equivalent to:
// select( coreDataStore ).getEntityRecords( 'root', 'postType', { per_page: 4 } );
} );
_Parameters_
- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
_Returns_
- `EntityRecord[] | null`: Records.
### getTaxonomy
Returns information for a given taxonomy.
_Usage_
import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
const taxonomy = useSelect( ( select ) => {
return select( coreDataStore ).getTaxonomy( 'category' );
// Equivalent to:
// select( coreDataStore ).getEntityRecord( 'root', 'taxonomy', 'category' );
} );
_Parameters_
- taxonomy `string`
_Returns_
- `EntityRecord | undefined`: Record.
### getTaxonomies
Returns information for taxonomies.
_Usage_
import { useSelect } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
const taxonomies = useSelect( ( select ) => {
return select( coreDataStore ).getTaxonomies( { type: 'post' } );
// Equivalent to:
// select( coreDataStore ).getEntityRecords( 'root', 'taxonomy', { type: 'post' } );
} );
_Parameters_
- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
_Returns_
- `EntityRecord[] | null`: Records.
## Other Selectors
### canUser
Returns whether the current user can perform the given action on the given REST resource.
Calling this may trigger an OPTIONS request to the REST API via the `canUser()` resolver.
_Parameters_
- _state_ `State`: Data state.
- _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'.
- _resource_ `string | EntityResource`: Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }` or REST base as a string - `media`.
- _id_ `EntityRecordKey`: Optional ID of the rest resource to check.
_Returns_
- `boolean | undefined`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.
### canUserEditEntityRecord
Returns whether the current user can edit the given entity.
Calling this may trigger an OPTIONS request to the REST API via the `canUser()` resolver.
_Parameters_
- _state_ `State`: Data state.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Record's id.
_Returns_
- `boolean | undefined`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.
### getAuthors
> **Deprecated** since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
Returns all available authors.
_Parameters_
- _state_ `State`: Data state.
- _query_ `GetRecordsHttpQuery`: Optional object of query parameters to include with request. For valid query parameters see the [Users page](https://developer.wordpress.org/rest-api/reference/users/) in the REST API Handbook and see the arguments for [List Users](https://developer.wordpress.org/rest-api/reference/users/#list-users) and [Retrieve a User](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user).
_Returns_
- `ET.User[]`: Authors list.
### getAutosave
Returns the autosave for the post and author.
_Parameters_
- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `EntityRecordKey`: The id of the parent post.
- _authorId_ `EntityRecordKey`: The id of the author.
_Returns_
- `EntityRecord | undefined`: The autosave for the post and author.
### getAutosaves
Returns the latest autosaves for the post.
May return multiple autosaves since the backend stores one autosave per author for each post.
_Parameters_
- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `EntityRecordKey`: The id of the parent post.
_Returns_
- `Array< any > | undefined`: An array of autosaves for the post, or undefined if there is none.
### getBlockPatternCategories
Retrieve the list of registered block pattern categories.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `Array< any >`: Block pattern category list.
### getBlockPatterns
Retrieve the list of registered block patterns.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `Array< any >`: Block pattern list.
### getCurrentTheme
Return the current theme.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `any`: The current theme.
### getCurrentThemeGlobalStylesRevisions
> **Deprecated** since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post.
Returns the revisions of the current global styles theme.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `Array< object > | null`: The current global styles.
### getCurrentUser
Returns the current user.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `ET.User< 'view' >`: Current user object.
### getDefaultTemplateId
Returns the default template use to render a given query.
_Parameters_
- _state_ `State`: Data state.
- _query_ `TemplateQuery`: Query.
_Returns_
- `string`: The default template id for the given query.
### getEditedEntityRecord
Returns the specified entity record, merged with its edits.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `ET.Updatable< EntityRecord > | false`: The entity record, merged with its edits.
### getEmbedPreview
Returns the embed preview for the given URL.
_Parameters_
- _state_ `State`: Data state.
- _url_ `string`: Embedded URL.
_Returns_
- `any`: Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
### getEntitiesByKind
> **Deprecated** since WordPress 6.0. Use getEntitiesConfig instead
Returns the loaded entities for the given kind.
_Parameters_
- _state_ `State`: Data state.
- _kind_ `string`: Entity kind.
_Returns_
- `Array< any >`: Array of entities with config matching kind.
### getEntitiesConfig
Returns the loaded entities for the given kind.
_Parameters_
- _state_ `State`: Data state.
- _kind_ `string`: Entity kind.
_Returns_
- `Array< any >`: Array of entities with config matching kind.
### getEntity
> **Deprecated** since WordPress 6.0. Use getEntityConfig instead
Returns the entity config given its kind and name.
_Parameters_
- _state_ `State`: Data state.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
_Returns_
- `any`: Entity config
### getEntityConfig
Returns the entity config given its kind and name.
_Parameters_
- _state_ `State`: Data state.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
_Returns_
- `any`: Entity config
### getEntityRecord
Returns the Entity's record object by key. Returns `null` if the value is not yet received, undefined if the value entity is known to not exist, or the entity object if it exists and is received.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
- _query_ `GetRecordsHttpQuery`: Optional query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available "Retrieve a [Entity kind]".
_Returns_
- `EntityRecord | undefined`: Record.
### getEntityRecordEdits
Returns the specified entity record's edits.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `Optional< any >`: The entity record's edits.
### getEntityRecordNonTransientEdits
Returns the specified entity record's non transient edits.
Transient edits don't create an undo level, and are not considered for change detection. They are defined in the entity's config.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `Optional< any >`: The entity record's non transient edits.
### getEntityRecords
Returns the Entity's records.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
_Returns_
- `EntityRecord[] | null`: Records.
### getEntityRecordsTotalItems
Returns the Entity's total available records for a given query (ignoring pagination).
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
_Returns_
- `number | null`: number | null.
### getEntityRecordsTotalPages
Returns the number of available pages for the given query.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
_Returns_
- `number | null`: number | null.
### getLastEntityDeleteError
Returns the specified entity record's last delete error.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Record ID.
_Returns_
- `any`: The entity record's save error.
### getLastEntitySaveError
Returns the specified entity record's last save error.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `any`: The entity record's save error.
### getRawEntityRecord
Returns the entity's record object by key, with its attributes mapped to their raw values.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `EntityRecord | undefined`: Object with the entity's raw attributes.
### getRedoEdit
> **Deprecated** since 6.3
Returns the next edit from the current undo offset for the entity records edits history, if any.
_Parameters_
- _state_ `State`: State tree.
_Returns_
- `Optional< any >`: The edit.
### getReferenceByDistinctEdits
Returns a new reference when edited values have changed. This is useful in inferring where an edit has been made between states by comparison of the return values using strict equality.
_Usage_
const hasEditOccurred = (
getReferenceByDistinctEdits( beforeState ) !==
getReferenceByDistinctEdits( afterState )
);
_Parameters_
- _state_ Editor state.
_Returns_
- A value whose reference will change only when an edit occurs.
### getRevision
Returns a single, specific revision of a parent entity.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordKey_ `EntityRecordKey`: The key of the entity record whose revisions you want to fetch.
- _revisionKey_ `EntityRecordKey`: The revision's key.
- _query_ `GetRecordsHttpQuery`: Optional query. If requesting specific fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [entity kind]".
_Returns_
- `RevisionRecord | Record< PropertyKey, never > | undefined`: Record.
### getRevisions
Returns an entity's revisions.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordKey_ `EntityRecordKey`: The key of the entity record whose revisions you want to fetch.
- _query_ `GetRecordsHttpQuery`: Optional query. If requesting specific fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [Entity kind]".
_Returns_
- `RevisionRecord[] | null`: Record.
### getThemeSupports
Return theme supports data in the index.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `any`: Index data.
### getUndoEdit
> **Deprecated** since 6.3
Returns the previous edit from the current undo offset for the entity records edits history, if any.
_Parameters_
- _state_ `State`: State tree.
_Returns_
- `Optional< any >`: The edit.
### getUserPatternCategories
Retrieve the registered user pattern categories.
_Parameters_
- _state_ `State`: Data state.
_Returns_
- `Array< UserPatternCategory >`: User patterns category array.
### getUserQueryResults
Returns all the users returned by a query ID.
_Parameters_
- _state_ `State`: Data state.
- _queryID_ `string`: Query ID.
_Returns_
- `ET.User< 'edit' >[]`: Users list.
### hasEditsForEntityRecord
Returns true if the specified entity record has edits, and false otherwise.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `boolean`: Whether the entity record has edits or not.
### hasEntityRecord
Returns true if a record has been received for the given set of parameters, or false otherwise.
Note: This action does not trigger a request for the entity record from the API if it's not available in the local state.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
- _query_ `GetRecordsHttpQuery`: Optional query.
_Returns_
- `boolean`: Whether an entity record has been received.
### hasEntityRecords
Returns true if records have been received for the given set of parameters, or false otherwise.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _query_ `GetRecordsHttpQuery`: Optional terms query. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
_Returns_
- `boolean`: Whether entity records have been received.
### hasFetchedAutosaves
Returns true if the REST request for autosaves has completed.
_Parameters_
- _state_ `State`: State tree.
- _postType_ `string`: The type of the parent post.
- _postId_ `EntityRecordKey`: The id of the parent post.
_Returns_
- `boolean`: True if the REST request was completed. False otherwise.
### hasRedo
Returns true if there is a next edit from the current undo offset for the entity records edits history, and false otherwise.
_Parameters_
- _state_ `State`: State tree.
_Returns_
- `boolean`: Whether there is a next edit or not.
### hasRevision
Returns true if a revision has been received for the given set of parameters, or false otherwise.
Note: This does not trigger a request for the revision from the API if it's not available in the local state.
_Parameters_
- _state_ `State`: State tree
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordKey_ `EntityRecordKey`: The key of the entity record whose revision you want to check.
- _revisionKey_ `EntityRecordKey`: The revision's key.
- _query_ `GetRecordsHttpQuery`: Optional query.
_Returns_
- `boolean`: Whether a revision has been received.
### hasUndo
Returns true if there is a previous edit from the current undo offset for the entity records edits history, and false otherwise.
_Parameters_
- _state_ `State`: State tree.
_Returns_
- `boolean`: Whether there is a previous edit or not.
### isAutosavingEntityRecord
Returns true if the specified entity record is autosaving, and false otherwise.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Record ID.
_Returns_
- `boolean`: Whether the entity record is autosaving or not.
### isDeletingEntityRecord
Returns true if the specified entity record is deleting, and false otherwise.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Record ID.
_Returns_
- `boolean`: Whether the entity record is deleting or not.
### isPreviewEmbedFallback
Determines if the returned preview is an oEmbed link fallback.
WordPress can be configured to return a simple link to a URL if it is not embeddable. We need to be able to determine if a URL is embeddable or not, based on what we get back from the oEmbed preview API.
_Parameters_
- _state_ `State`: Data state.
- _url_ `string`: Embedded URL.
_Returns_
- `boolean`: Is the preview for the URL an oEmbed link fallback.
### isRequestingEmbedPreview
Returns true if a request is in progress for embed preview data, or false otherwise.
_Parameters_
- _state_ `State`: Data state.
- _url_ `string`: URL the preview would be for.
_Returns_
- `boolean`: Whether a request is in progress for an embed preview.
### isSavingEntityRecord
Returns true if the specified entity record is saving, and false otherwise.
_Parameters_
- _state_ `State`: State tree.
- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _recordId_ `EntityRecordKey`: Is omitted for keyless entities.
_Returns_
- `boolean`: Whether the entity record is saving or not.
## Actions
### addEntities
Returns an action object used in adding new entities.
_Parameters_
- _entities_ `Array< EntityConfig >`: Entities received.
_Returns_
- `ActionOf< 'ADD_ENTITIES' >`: Action object.
### clearEntityRecordEdits
Action triggered to clear all edits from an entity record.
_Parameters_
- _kind_ `string`: Kind of the entity.
- _name_ `string`: Name of the entity.
- _recordId_ `number | string`: Is omitted for keyless entities.
_Returns_
- Action object.
### deleteEntityRecord
Action triggered to delete an entity record.
_Parameters_
- _kind_ `string`: Kind of the deleted entity.
- _name_ `string`: Name of the deleted entity.
- _recordId_ `string | number`: Record ID of the deleted entity.
- _query_ `Query | null`: Special query parameters for the DELETE API call.
- _options_ `DeleteEntityRecordOptions`: Delete options.
- _options.\_\_unstableFetch_ `DeleteEntityRecordOptions[ '__unstableFetch' ]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.
- _options.throwOnError_ `DeleteEntityRecordOptions[ 'throwOnError' ]`: If false, this action suppresses all the exceptions. Defaults to false.
### editEntityRecord
Returns an action object that triggers an edit to an entity record.
_Parameters_
- _kind_ `string`: Kind of the edited entity record.
- _name_ `string`: Name of the edited entity record.
- _recordId_ `number | string | undefined`: Pass `undefined` for keyless entities.
- _edits_ `object`: The edits.
- _options_ `EditEntityRecordOptions`: Options for the edit.
- _options.undoIgnore_ `EditEntityRecordOptions[ 'undoIgnore' ]`: Whether to ignore the edit in undo history or not.
- _options.isCached_ `EditEntityRecordOptions[ 'isCached' ]`: Whether the edit is transient (e.g. typing). Transient edits are staged and eventually merged into the preceding undo level instead of creating a new one.
_Returns_
- Action object.
### receiveDefaultTemplateId
Returns an action object used to set the template for a given query.
_Parameters_
- _query_ `Query`: The lookup query.
- _templateId_ `string`: The resolved template id.
_Returns_
- `ActionOf< 'RECEIVE_DEFAULT_TEMPLATE' >`: Action object.
### receiveEntityRecords
Returns an action object used in signalling that entity records have been received.
_Parameters_
- _kind_ `string`: Kind of the received entity record.
- _name_ `string`: Name of the received entity record.
- _records_ `object | Array< object >`: Records received.
- _query_ `Query | null | undefined`: Query Object.
- _invalidateCache_ `boolean | null`: Should invalidate query caches.
- _edits_ `object | null | undefined`: Edits to reset.
- _meta_ `QueriedMeta | null | undefined`: Meta information about pagination.
_Returns_
- Action object.
### receiveNavigationFallbackId
Returns an action object signalling that the fallback Navigation Menu id has been received.
_Parameters_
- _fallbackId_ `number | null | undefined`: the id of the fallback Navigation Menu
_Returns_
- `ActionOf< 'RECEIVE_NAVIGATION_FALLBACK_ID' >`: Action object.
### receiveRevisions
Action triggered to receive revision items.
_Parameters_
- _kind_ `string`: Kind of the received entity record revisions.
- _name_ `string`: Name of the received entity record revisions.
- _recordKey_ `number | string`: The key of the entity record whose revisions you want to fetch.
- _records_ `object | Array< object >`: Revisions received.
- _query_ `Query | null`: Query Object.
- _invalidateCache_ `boolean | null`: Should invalidate query caches.
- _meta_ `QueriedMeta | null`: Meta information about pagination.
### receiveThemeSupports
> **Deprecated** since WP 5.9, this is not useful anymore, use the selector directly.
Returns an action object used in signalling that the index has been received.
_Returns_
- `{ type: 'DO_NOTHING'; }`: Action object.
### receiveUploadPermissions
> **Deprecated** since WP 5.9, use receiveUserPermission instead.
Returns an action object used in signalling that Upload permissions have been received.
_Parameters_
- _hasUploadPermissions_ `boolean`: Does the user have permission to upload files?
_Returns_
- `ActionOf< 'RECEIVE_USER_PERMISSION' >`: Action object.
### redo
Action triggered to redo the last undone edit to an entity record, if any.
### saveEditedEntityRecord
Action triggered to save an entity record's edits.
_Parameters_
- _kind_ `string`: Kind of the entity.
- _name_ `string`: Name of the entity.
- _recordId_ `number | string`: Is omitted for keyless entities.
- _options_ `SaveEntityRecordOptions`: Saving options.
### saveEntityRecord
Action triggered to save an entity record.
_Parameters_
- _kind_ `string`: Kind of the received entity.
- _name_ `string`: Name of the received entity.
- _record_ `object`: Record to be saved.
- _options_ `SaveEntityRecordOptions`: Saving options.
- _options.isAutosave_ `SaveEntityRecordOptions[ 'isAutosave' ]`: Whether this is an autosave.
- _options.\_\_unstableFetch_ `SaveEntityRecordOptions[ '__unstableFetch' ]`: Internal use only. Function to call instead of `apiFetch()`. Must return a promise.
- _options.throwOnError_ `SaveEntityRecordOptions[ 'throwOnError' ]`: If false, this action suppresses all the exceptions. Defaults to false.
### undo
Action triggered to undo the last edit to an entity record, if any.