Repository navigation
Concurrent Edits
Arun Prakash edited this page Nov 3, 2026
·
1 revision
Two people (or two devices) load the same post, both edit it, both save: the second save silently overwrites the first. updateIfUnmodified refuses the save when the item changed on the server after you loaded it.
final post = (await client.posts.retrieve(RetrievePostRequest(id: 42, context: RequestContext.edit))).dataOrThrow();
// ... the user edits ...
final r = await client.posts.updateIfUnmodified(
UpdatePostRequest(id: post.id, title: 'Renamed'),
lastModifiedGmt: post.modifiedGmt!,
);
if (r case WordpressFailureResponse(:final error?) when error.code == UpdateOperation.conflictErrorCode) {
// someone saved it since you loaded it: reload, merge, ask the user
} else if (r.isSuccessful) {
// saved
}It is available on every built-in interface with an update operation (posts, pages, media, navigations, ...). client.resource<T> has plain update only.
- A small GET for the item with
_fields=modified_gmt&context=edit. It bypassesCacheMiddleware, so a cached copy never hides a newer save. - If its
modified_gmtdiffers fromlastModifiedGmt, nothing is sent and a failure is returned. - Otherwise the normal update is sent.
| Failure | Status | error.code |
|---|---|---|
| Changed on the server | 409 |
UpdateOperation.conflictErrorCode (wp_client_conflict) |
The item has no modified_gmt
|
412 |
UpdateOperation.noModifiedErrorCode (wp_client_no_modified_gmt) |
| The check itself failed (offline, 404, 401, ...) | that response's | that response's |
- WordPress has no conditional update, so a save that lands between the check and the update is not detected. The window is one round trip.
- Only resources with
modified_gmtcan be checked: posts, pages, media and navigations. Terms, users, comments and templates fail withnoModifiedErrorCode; useupdatefor those. - Pass the
modifiedGmtof the copy the user edited, not of a later reload. -
modified_gmthas one second resolution.
Getting started
- Usage
- Bootstrap and Configuration
- Authorization
- Browser Sign-In
- WordPress.com and Jetpack
- Multisite
- Supported REST Methods
Requests and data
- Sending Requests
- Error Handling and Responses
- Fluent Queries
- Interfaces and Extensions
- Custom Post Types
- Model Generator
- Meta and ACF
- Concurrent Edits
- Batch Requests
- Embed and Fields
- Pagination and Finders
- Parallel Requests
- Streaming and Polling
- Pattern Directory Items
Behaviour
- Retries
- Caching
- Request De-duplication and Concurrency
- Middlewares
- Logging
- Offline Write Queue
- Events and Statistics
Other APIs
Extend and test
Reference