Updating the SiteURL or Home Link for wordpress

Updating the SiteURL or Home Link for wordpress

Here and there I have come up with a problem to solve when either deploying word press sites or beginning to maintain sites that are live. My first step is usually to back up the site locally and attempt to fix the issues or create additional functionality as the situation calls for. The problem is that, the live site is usually not the same url that I am using. For instance, I can not use the same domain unless I want to continually be modifying my dns or hosts files. My solution is to usually have an automated way to create an aliasmatch such as the following: devsite.com/devhost where devhost is the domain. This is usually much different than livesite.com/blog or livesite.com.

Updating the SiteURL or Home Link for wordpress – Details

In order to find this information, my first thoughts were to check the wp-config.php, but the information in there is the database configuration as well as some keys used for parts of wordpress that are outside the scope of this article. I was able to locate the information in the database itself which was pretty straightforward.

Updating the SiteURL or Home Link for wordpress – Searching the database

So in order to search the database – I used the mysql show table command to get all list of tables.

+-----------------------+
| Tables_in_ahi_blog       |                                                                                               
+-----------------------+                                                                                               
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
11 rows in set (0.00 sec)

It was evident that I would need to take a look in the ‘wp_options’ table. So I performed the following query to explain about the table.

DESCRIBE wp_options;

+--------------+---------------------+ ...
| Field        | Type                | ...
+--------------+---------------------+ ...
| option_id    | bigint(20) unsigned | ...
| blog_id      | int(11)             | ...
| option_name  | varchar(64)         | ...
| option_value | longtext            | ...
| autoload     | varchar(20)         | ...
+--------------+---------------------+ ...
5 rows in set (0.00 sec)

Once I was presented with this information I simply did a quick query such as the following:
SELECT * FROM wp_options WHERE option_value LIKE ‘%devsite.com%’;
which gave me the ids 1 and 37 for the option_names siteurl and ‘home’;
You should know that there were more values to look through and I am not sure, but am confident to a certain degree that others findings will be similar. I then basically did a simple update wp_options SET option_value=’http://www.livesite.com’ WHERE option_id IN ( 1,37); to update the values.

Good Luck! and make sure to back up the db first in case you have issues.

ttessier

About ttessier

Professional Developer and Operator of SwhistleSoft
This entry was posted in Content Management Systems, MYSQL, Wordpress Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *