Adds an admin view where editors search for text across configured collections and replace it after reviewing a preview of every match. It builds on a fork of the official search plugin, using its search collection as an index. Replacements run as the signed-in user with access control applied, and on draft-enabled collections they are saved as new drafts. Requires Payload 3.86 or later and Next.js 15.2.9 or later.
Find and replace text across Payload CMS collections, including Lexical rich text. Forked from @payloadcms/plugin-search.
Installation
npm i @fourdigit/payload-plugin-search-replace0
Stars
0
Forks
1
Open Issues
1 months ago
Last Updated
0
Weekly Downloads
v
npm Version
Dependencies
00 since Oct 18
| Date | Stars |
|---|---|
| Dec 6, 2026 | 0 |
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
| Nov 7, 2026 | 0 |
| Nov 6, 2026 | 0 |
| Nov 5, 2026 | 0 |
| Nov 4, 2026 | 0 |
| Nov 3, 2026 | 0 |
| Nov 2, 2026 | 0 |
| Nov 1, 2026 | 0 |
| Oct 31, 2026 | 0 |
| Oct 30, 2026 | 0 |
| Oct 29, 2026 | 0 |
| Oct 28, 2026 | 0 |
| Oct 27, 2026 | 0 |
| Oct 26, 2026 | 0 |
| Oct 25, 2026 | 0 |
| Oct 24, 2026 | 0 |
| Oct 23, 2026 | 0 |
| Oct 22, 2026 | 0 |
| Oct 21, 2026 | 0 |
| Oct 20, 2026 | 0 |
| Oct 19, 2026 | 0 |
| Oct 18, 2026 | 0 |
Trends appear after 7 days of data. Daily snapshots have not started yet.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1426527062-root)<a href="https://payloaddirectory.dev/plugins/1426527062-root"><img src="https://payloaddirectory.dev/badge/1426527062-root.svg" alt="Payload Directory"></a>README
Find and replace text across Payload CMS collections — plain text, textareas and Lexical rich text — with a preview of every change before anything is saved.
A fork of @payloadcms/plugin-search: its search collection becomes an index of every document's text, used to find candidates quickly. See FORK.md.
text, textarea, hasMany text and Lexical richText fields, including fields inside groups, tabs, arrays and blocksABC matches ABC and ガ matches ガ — only the matched range is replacedoverrideAccess: false as the signed-in user, so collection, document and field access (tenants, departments, roles…) apply/admin/search-replace, with a nav link. English and Japanese^3.86.0, Next.js >=15.2.9, React 19@payloadcms/ui, @payloadcms/next and @payloadcms/translations as direct dependencies, at the same version as payloadpnpm add @fourdigit/payload-plugin-search-replace
// payload.config.ts
import { searchReplacePlugin } from '@fourdigit/payload-plugin-search-replace'
export default buildConfig({
// ...
plugins: [
searchReplacePlugin({
collections: ['pages', 'posts'],
replace: {
canUseRegex: ({ req }) => Boolean(req.user?.roles?.includes('admin')),
},
}),
],
})
Then regenerate the import map and, for existing content, build the index once:
pnpm payload generate:importmap
The index is filled when documents are saved. For documents that existed before the plugin was installed, run a reindex (see Access to the index).
Open Search & Replace from the admin nav, or go to /admin/search-replace.

replace.canUseRegex).Press Search. Nothing is saved yet.

Each document is listed with every match, the field it is in (its label, plus the path for fields inside groups and arrays), and the text before and after the change. Untick a match, or a whole document, to leave it out. Edit opens the document.
A match that crosses formatting or a link in rich text (here, さくら + ポイント in bold) is shown but can't be ticked: replacing it would lose the formatting, so it says fix by hand.

Replace selected asks for confirmation, then saves each document as the signed-in user, with that user's access rights.

The message counts what happened to each document: updated, unchanged, changed since the search (another edit came first; nothing was written, so search again), or failed. The search then runs again, so what's left is what still matches, like the match to fix by hand.

On collections with drafts, the replacement is a new draft and the published version stays as it is. Review it in the document's Versions tab and publish it through your usual workflow. The version history is also the record of what was replaced and by whom.

With Ignore full-width / half-width, ABCD also finds ABCD, and ガ finds ガ. Only the matched characters are replaced; the text around them keeps its width.
The screenshots come from the dev app (dev/) and can be regenerated with node dev/screenshots.mjs (see the comment at the top of the file).
All options of @payloadcms/plugin-search are accepted. Defaults that differ from upstream are marked.
| Option | Type | Default | |
|---|---|---|---|
collections | string[] | — | Collections to index and search |
fields.exclude | string[] | DEFAULT_EXCLUDE (below) | Glob patterns on the field path (names only, no array indices, e.g. layout.content). * matches one segment, ** any number. Replaces the defaults; spread DEFAULT_EXCLUDE to keep them |
fields.include | ({ collection, field, schemaPath }) => boolean | undefined | — | Decide per field; true also brings back a hidden field. undefined falls back to the rules below |
replace.access | ({ req }) => boolean | Promise<boolean> | users who can open the admin panel | Who can open the view and call the endpoints. Document access still applies |
replace.canUseRegex | ({ req }) => boolean | Promise<boolean> | nobody | Who can search with regular expressions |
replace.maxApplyDocs | number | no limit | Most documents one apply request may change |
replace.disableAdminView | boolean | false | Leave out the admin view and nav link; the endpoints stay |
syncDrafts | boolean | true (upstream false) | The index has to hold draft text, since replacements work on drafts |
deleteDrafts | boolean | false (upstream true) |
hidden, admin.hidden or admin.disabled, or inside such a field): editors can't see what a replacement would do to them. This covers Payload's upload fields (filename, mimeType, sizes…) and storage plugins' prefix.DEFAULT_EXCLUDE:
**.slug, **.urlbreadcrumbs.** — added by @payloadcms/plugin-nested-docs and rebuilt from the parent pages on every savestripeID — added by @payloadcms/plugin-stripe; the id of the synced Stripe objectTo add your own patterns and keep these:
import { DEFAULT_EXCLUDE, searchReplacePlugin } from '@fourdigit/payload-plugin-search-replace'
searchReplacePlugin({
collections: ['pages'],
fields: { exclude: [...DEFAULT_EXCLUDE, 'legacyId', 'internal.**'] },
})
The search collection lists text from every indexed document, drafts included, across tenants and departments. So by default nobody can read, update or delete it through the API (upstream allows public reads), and its content / contentRaw fields are never readable, even if you open the collection up. Syncing and search & replace use the Local API and do not need API access.
To see the collection in the admin panel and use upstream's Reindex button, give your administrators access:
searchReplacePlugin({
collections: ['pages', 'posts'],
searchOverrides: {
access: {
read: isAdmin,
update: isAdmin,
delete: isAdmin,
},
},
})
Only give reindex to users who can read every indexed document: a reindex rebuilds the index with the documents the user can read.
The admin view uses these; you can call them yourself.
| Endpoint | Body | Returns |
|---|---|---|
GET /api/search-replace/capabilities | — | { canUseRegex, collections, maxApplyDocs } |
POST /api/search-replace/preview | { find, replace?, mode?: 'text' | 'regex', caseSensitive?, normalizeWidth?, locale?, collections? } | { documents: [{ collection, id, title, updatedAt, matches: [{ id, fieldLabel?, fieldPath, before, text, after, replacement, replaceable, reason? }] }], totals } |
POST /api/search-replace/apply | the preview query plus documents: [{ collection, id, matchIds, updatedAt? }] | { results: [{ collection, id, status, appliedIds, skippedIds, message? }] } |
status is updated, unchanged, stale (the document changed after the preview; nothing was written) or error. Match ids that were not replaced — changed since the preview, needing a manual fix, or kept by field-level update access — are listed in skippedIds.
\1) and lookaround ((?=…), (?<=…)) are not supported. Replacements support $1, $<name>, $& and $$.BlocksFeature nodes) are not searched.\, and all regular expressions, read every document of the selected collections instead of narrowing with the index.平 in ㍻) is shown but has to be fixed by hand.pnpm install
pnpm dev # dev app on http://localhost:3000 ([email protected] / test)
pnpm test:int # unit and integration tests (in-memory SQLite)
pnpm lint
pnpm typecheck
pnpm build && pnpm check:pack # packs the package and checks what would be published
DATABASE_URL in dev/.env picks the adapter: postgres://…, mongodb://…, or unset for SQLite. CI (.github/workflows/ci.yml) runs lint, types, the tests on SQLite and PostgreSQL 16, and the pack check on every pull request.
MIT. Includes code from @payloadcms/plugin-search, © Payload CMS, Inc. See LICENSE.md.
payload cmdk
Keyboard-driven command menu for navigating collections, globals and custom actions in the Payload admin
75528/wk32v3
payload plugin info tooltip
Show field help as an info icon tooltip next to the label instead of a description under the field
6738/wk7v3 v4
payload plugin presets
Save and apply reusable block configurations as presets from the Payload admin blocks drawer
786.7k/wk37v3
payload dynamic
Define record types, fields and relationships in the Payload admin and store them in native SQL-backed collections
78865/wk0v4
payload puck
Puck drag-and-drop visual page builder embedded in the Payload admin for building pages
772.5k/wk117v3
payload nested docs page tree
Page tree list view for nested docs collections with drag and drop, status badges and live or preview links
771.6k/wk35v3