Search & replace

Run a search-replace operation across the WordPress database.


POST/api/servers/{server}/sites/{id}/wordpress/search-replace

Search & replace

Runs a WP-CLI search-replace operation across all WordPress database tables with the site's prefix. Useful for domain migrations, URL changes, or bulk content updates. Supports dry-run mode to preview changes before applying them. Requires WP-CLI to be installed on the server.

The command uses the --precise and --all-tables-with-prefix flags for accurate replacements across serialized data.

Required attributes

  • Name
    search
    Type
    string
    Description

    The string to search for (e.g. https://old-domain.com).

  • Name
    replace
    Type
    string
    Description

    The replacement string (e.g. https://new-domain.com). Can be empty to remove occurrences.

Optional attributes

  • Name
    dry_run
    Type
    boolean
    Description

    When set to true (default), the command will only report what changes would be made without actually modifying the database. Set to false to apply the changes.

Query parameters

  • Name
    ondemand
    Type
    boolean
    Description

    When set to true, the command runs synchronously and returns the result directly. When omitted or false (default), the action is queued and processed in the background.

Request (dry run)

POST
/api/servers/{server}/sites/{id}/wordpress/search-replace
curl -X POST "https://ploi.io/api/servers/{server}/sites/{id}/wordpress/search-replace?ondemand=true" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"search": "https://old-domain.com", "replace": "https://new-domain.com", "dry_run": true}'

Response

{
  "output": "+------------------+-----------------------+--------------+------+\n| Table            | Column                | Replacements | Type |\n+------------------+-----------------------+--------------+------+\n| wp_options       | option_value          | 12           | PHP  |\n| wp_posts         | post_content          | 48           | PHP  |\n| wp_posts         | guid                  | 96           | PHP  |\n| wp_postmeta      | meta_value            | 23           | PHP  |\n+------------------+-----------------------+--------------+------+\n"
}