Skip to content

Instantly share code, notes, and snippets.

@haze83
Last active February 1, 2024 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haze83/e96770933e063922b8a6096e995d6a98 to your computer and use it in GitHub Desktop.
Save haze83/e96770933e063922b8a6096e995d6a98 to your computer and use it in GitHub Desktop.
WP Search Replace domain
wp search-replace old.domain.ch new.domain.ch --recurse-objects --all-tables --skip-plugins --skip-themes
SET @search = 'https://old.domain.ch' COLLATE utf8mb4_unicode_ci;
SET @replace = 'https://new.domain.ch' COLLATE utf8mb4_unicode_ci;
SELECT `option_value`, REPLACE(`option_value`, @search, @replace) AS option_value_replaced
FROM `wp_options`
WHERE
`option_name` = 'home'
OR `option_name` = 'siteurl';
UPDATE `wp_options`
SET `option_value` = REPLACE(option_value, @search, @replace)
WHERE
`option_name` = 'home'
OR `option_name` = 'siteurl';
SELECT
`post_content`, REPLACE(`post_content`, @search, @replace) AS post_content_replaced,
`post_excerpt`, REPLACE(`post_excerpt`, @search, @replace) AS post_excerpt_replaced
FROM `wp_posts`
WHERE
`post_content` LIKE CONCAT('%', @search, '%')
OR `post_excerpt` LIKE CONCAT('%', @search, '%');
UPDATE `wp_posts`
SET `post_content` = REPLACE(`post_content`, @search, @replace),
`post_excerpt` = REPLACE(`post_excerpt`, @search, @replace)
WHERE
`post_content` LIKE CONCAT('%', @search, '%')
OR `post_excerpt` LIKE CONCAT('%', @search, '%');
SELECT
`meta_value`, REPLACE(`meta_value`, @search, @replace) AS meta_value_replaced
FROM `wp_postmeta`
WHERE
`meta_value` LIKE CONCAT('%', @search, '%');
UPDATE `wp_postmeta`
SET `meta_value` = REPLACE(`meta_value`, @search, @replace)
WHERE
`meta_value` LIKE CONCAT('%', @search, '%');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment