Skip to content

Instantly share code, notes, and snippets.

@hluker
Last active June 5, 2020 10:19
Show Gist options
  • Select an option

  • Save hluker/69e90892988cb0595b985d7cf4fb69e9 to your computer and use it in GitHub Desktop.

Select an option

Save hluker/69e90892988cb0595b985d7cf4fb69e9 to your computer and use it in GitHub Desktop.
useful sql commands

wordpress - find and replace domains

UPDATE wp_options SET option_value = replace(option_value, 'http://oldsite.com', 'http://newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'http://oldsite.com', 'http://newsite.com');
UPDATE wp_links SET link_url = replace(link_url, 'http://oldsite.com', 'http://newsite.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://oldsite.com', 'http://newsite.com');
UPDATE wp_posts SET guid = replace(guid, 'http://oldsite.com', 'http://newsite.com');
@hluker
Copy link
Copy Markdown
Author

hluker commented May 21, 2020

if you want to blow up your media library

DELETE FROM `wp_posts` WHERE `post_type` = "attachment";
DELETE FROM `wp_postmeta` WHERE `meta_key` = "_wp_attached_file";
DELETE FROM `wp_postmeta` WHERE `meta_key` = "_wp_attachment_metadata";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment