Last active
September 23, 2018 15:03
-
-
Save blogtutor/14d80b3eca178fe1115f7400f1e72e15 to your computer and use it in GitHub Desktop.
Search & Replace with WP-CLI
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
| # Sample code to run search & replace in your WordPress database from the command line with WP-CLI | |
| # Use at your own risk! I make no warranties that this will actually work properly and not blow up your site! (I recommend trying this on a development server first.) | |
| # Make a database backup first with "wp db export" | |
| # Replace "domain.com" with your domain (also include www if used) | |
| # https://developer.wordpress.org/cli/commands/search-replace/ | |
| # Simple change from http to https | |
| wp search-replace 'http://domain.com' 'https://domain.com' --skip-columns=guid | |
| # Remove /year/month/ from permalinks | |
| wp search-replace 'https://domain.com/([0-9]{4})/([0-9]{2})/' 'https://domain.com/' --regex --skip-columns=guid | |
| # Remove /year/month/day/ from permalinks | |
| wp search-replace 'https://domain.com/([0-9]{4})/([0-9]{2})/([0-9]{2})/' 'https://domain.com/' --regex --skip-columns=guid | |
| # Remove /year/month/ and trailing ".html" from permalinks | |
| wp search-replace 'https://domain.com/([0-9]{4})/([0-9]{2})/(.*).html' 'https://domain.com/\3/' --regex --skip-columns=guid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment