Skip to content

Instantly share code, notes, and snippets.

@mateuslopes
Last active February 19, 2020 13:43
Show Gist options
  • Save mateuslopes/2864426 to your computer and use it in GitHub Desktop.
Save mateuslopes/2864426 to your computer and use it in GitHub Desktop.
SQL+Wordpress: Changing WP Site Url
SET NAMES 'utf8mb4';
SET CHARACTER SET 'utf8mb4';
SET @origin_url = 'http://localhost/origem';
SET @destiny_url = 'http://localhost/destino';
UPDATE wp_options
SET option_value = REPLACE(option_value, @origin_url, @destiny_url)
WHERE option_value LIKE (CONCAT('%',@origin_url,'%'));
UPDATE wp_posts
SET
post_content = REPLACE(post_content, @origin_url, @destiny_url),
post_excerpt = REPLACE(post_excerpt, @origin_url, @destiny_url),
guid = REPLACE(guid, @origin_url, @destiny_url)
WHERE
post_content LIKE (CONCAT('%',@origin_url,'%'))
OR
post_excerpt LIKE (CONCAT('%',@origin_url,'%'))
OR
guid LIKE (CONCAT('%',@origin_url,'%'));
UPDATE wp_postmeta
SET meta_value = REPLACE(meta_value, @origin_url, @destiny_url)
WHERE meta_value LIKE (CONCAT('%',@origin_url,'%'));
UPDATE wp_termmeta
SET meta_value = REPLACE(meta_value, @origin_url, @destiny_url)
WHERE meta_value LIKE (CONCAT('%',@origin_url,'%'));
#UPDATE wp_taxonomymeta
#SET meta_value = REPLACE(meta_value, @origin_url, @destiny_url)
#WHERE meta_value LIKE (CONCAT('%',@origin_url,'%'));
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment