To setup an existing Wordpress DB into the new server we should run these minimal 2 queries to adopt all required URL changes. It is exactly changing the Site URLs from old one to new one.
update `wp_options` set `option_value` = replace(`option_value`,'<SOURCE URL>' , '<DESTINATION URL>')
update `wp_posts` set `post_content` = replace( `post_content`,'<SOURCE URL>' , '<DESTINATION URL>'), `guid` = replace( `guid`,'<SOURCE URL>' , '<DESTINATION URL>')
Here wp may need to changed with required prefix.
We have changed only 2 tables
A sample Php code is available here.
If Page/post is using Permalink other than post/page id, e.g. Post Name, you have to go to Setting -> Permalink and re-save the settings to be effective in new site.
update `wp_options` set `option_value` = replace(`option_value`,'<SOURCE URL>' , '<DESTINATION URL>')
update `wp_posts` set `post_content` = replace( `post_content`,'<SOURCE URL>' , '<DESTINATION URL>'), `guid` = replace( `guid`,'<SOURCE URL>' , '<DESTINATION URL>')
Here wp may need to changed with required prefix.
We have changed only 2 tables
- wp_options and
- wp_posts
A sample Php code is available here.
If Page/post is using Permalink other than post/page id, e.g. Post Name, you have to go to Setting -> Permalink and re-save the settings to be effective in new site.