Last active
September 27, 2024 10:56
-
-
Save estevan-ulian/fa79a95d2e5e5df7a1891f32ad97c546 to your computer and use it in GitHub Desktop.
Updates URLs in the database of a wordpress site
This file contains hidden or 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 @prefix = 'wp_'; -- DEFINE TABLES PREFIX | |
| SET @old_url = 'http://old-site.com'; -- DEFINE THE OLD/CURRENT URL | |
| SET @new_url = 'http://new-site.com'; -- DEFINE THE NEW URL | |
| SET @query1 = CONCAT('UPDATE ', @prefix, 'options SET option_value = REPLACE(option_value, ''', @old_url, ''', ''', @new_url, ''') WHERE option_name = ''home'' OR option_name = ''siteurl'''); | |
| PREPARE stmt1 FROM @query1; | |
| EXECUTE stmt1; | |
| DEALLOCATE PREPARE stmt1; | |
| SET @query2 = CONCAT('UPDATE ', @prefix, 'posts SET post_content = REPLACE(post_content, ''', @old_url, ''', ''', @new_url, ''')'); | |
| PREPARE stmt2 FROM @query2; | |
| EXECUTE stmt2; | |
| DEALLOCATE PREPARE stmt2; | |
| SET @query3 = CONCAT('UPDATE ', @prefix, 'postmeta SET meta_value = REPLACE(meta_value, ''', @old_url, ''', ''', @new_url, ''')'); | |
| PREPARE stmt3 FROM @query3; | |
| EXECUTE stmt3; | |
| DEALLOCATE PREPARE stmt3; | |
| SET @query4 = CONCAT('UPDATE ', @prefix, 'links SET link_url = REPLACE(link_url, ''', @old_url, ''', ''', @new_url, ''')'); | |
| PREPARE stmt4 FROM @query4; | |
| EXECUTE stmt4; | |
| DEALLOCATE PREPARE stmt4; | |
| SET @query5 = CONCAT('UPDATE ', @prefix, 'comments SET comment_content = REPLACE(comment_content, ''', @old_url, ''', ''', @new_url, ''')'); | |
| PREPARE stmt5 FROM @query5; | |
| EXECUTE stmt5; | |
| DEALLOCATE PREPARE stmt5; | |
| SET @query6 = CONCAT('UPDATE ', @prefix, 'comments SET comment_author_url = REPLACE(comment_author_url, ''', @old_url, ''', ''', @new_url, ''')'); | |
| PREPARE stmt6 FROM @query6; | |
| EXECUTE stmt6; | |
| DEALLOCATE PREPARE stmt6; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment