Skip to main content
The WordPress editors manipulate entity records - objects representing posts, pages, users, templates, and other WordPress data. The @wordpress/core-data package manages these records and provides a unified undo/redo system across multiple simultaneous edits.

What Are Entities?

An entity represents a data source. Each item within the entity is called an entity record. Entities are defined in the core-data package and map to WordPress REST API endpoints.

Entity Configuration

Entities are configured with the following properties:

kind

Groups related entities together (e.g., root, postType):

name

Unique identifier within the kind:

baseURL

REST API endpoint path:

Accessing Entities

Entities are accessed using kind and name:

Dynamic Methods

For root kind entities, the package creates convenience methods:

Entity Record States

The core-data store tracks two versions of each entity record:

Persisted Record

The last state fetched from the backend:
This represents the saved state without any local modifications.

Edited Record

The persisted record with local edits applied:
Edited entity records contain raw values as strings, not objects with rendered and raw properties. This is because JavaScript cannot render server-side dynamic content.

Editing Entities

Basic Edit Flow

  1. Fetch the entity (automatically happens when you call a selector)
  2. Apply edits using editEntityRecord
  3. Save changes using saveEditedEntityRecord

Edit Tracking

The store maintains a list of edits for each record:

Complete Edit Example

Creating New Records

For new records without an ID, use saveEntityRecord instead:
Note the differences from editing:
  • Use saveEntityRecord (not saveEditedEntityRecord)
  • Pass the complete record object (not just an ID)
  • No editEntityRecord call needed

Undo/Redo System

The WordPress editors support simultaneous editing of multiple entity records. The undo/redo system tracks all changes across entities.

How It Works

When editing in the Site Editor:
  • Edit page title → Creates undo step
  • Edit template content → Creates undo step
  • Edit header template part → Creates undo step
  • Press undo → Reverts the last change

Undo/Redo Stack Structure

Each modification stores:
  • Entity kind and name: Identifies the entity (e.g., postType, page)
  • Entity Record ID: The specific record modified
  • Property: The modified property name (e.g., title)
  • From: Previous value (for undo)
  • To: New value (for redo)
Example stack:

Using Undo/Redo

Cached Changes

Not all edits are immediately added to the undo/redo stack. Some modifications are “cached” to avoid creating excessive undo levels.

When Cached Changes Are Used

  • Typing in text fields (creates undo level after a delay)
  • Rapid successive changes
  • Changes marked with isCached: true option

Transient Edits

Some edits don’t create undo levels at all:
Transient edits are defined in entity configuration and typically include:
  • UI state
  • Temporary values
  • Computed properties

Multiple Simultaneous Edits

The editor can edit multiple records at once:
When saving:

Entity Record Lifecycle

Best Practices

Always Use getEditedEntityRecord for Forms

Check for Edits Before Saving

Handle Save Errors

Clear Edits When Needed

Next Steps