Last active
February 1, 2024 07:13
-
-
Save haze83/e96770933e063922b8a6096e995d6a98 to your computer and use it in GitHub Desktop.
WP Search Replace domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wp search-replace old.domain.ch new.domain.ch --recurse-objects --all-tables --skip-plugins --skip-themes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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