[wp-hackers] change siteurl at DB level
andrew at graymerica.com
Tue Aug 24 20:18:32 UTC 2010
I have been trying to move a site from development.domain.com to domain.com all day and got fed up and wrote some SQL to make the change on the DB level.
I know that you can download the DB dump and fix it, but it causes some problems for me with UTF characters. Also some of my sites are pretty big now, with all the revisions, custom post types and what not.
If you run this command, you can pretty much change all of the stock tables.
This will not change all your plugins values, but saved me a ton of time. Took about 1 sec to run
#Change Domain in in Wordpress DB
#before you run this command in SQL (phpmyadmin)
# 1. Backup DB
# 2. Find and replace the text below in your text editor
#replace $old$ with the old domain name
#replace $new$ with the new domain name
update wp_postmeta set meta_value = replace(meta_value, '$old$' , '$new$') ;
update wp_posts set post_content = replace(post_content, '$old$' , '$new$') ;
update wp_options set option_value = replace(option_value, '$old$' , '$new$') ;
#end sql command
I would love it if there was an easy way to force wordpress to use a place holder for the domain and then replace in the correct one when it reads from the DB.
If I could find a filter that would filter every value from read and write to the db, I could do this very easy, but there is no filter for every value coming from the DB.
I just do not know why the SITEURL should be stored in the DB. Is there a pair of filters that I can use to replace a value in every read and write
More information about the wp-hackers