Solved

Need SQL statement for WordPress to fix WWW problem

Posted on 2014-09-14
3
233 Views
Last Modified: 2014-09-14
My client started their WordPress website with a domain and hard-coded it to not have a "www." in front of the domain. Unfortunately, this caused problems on the local "windows domain" network in the office. The LAN technician said that the website had to be changed to include "www." we did, and now we need to adjust all the references to images and pages in the website that currently do not have a "www.".

Therefore, I am looking for one or more SQL statements that I can execute in MyPHPAdmin to change all references of "http://domain.com" to "http://www.mydomain.com". This would be in at least these two fields of the wp_posts table:
post_content
GUID
There might be other fields in this table and there might be other tables to modify, too. I am not sure.

I am not an expert on MySQL, so I am not sure how to formulate the SQL statements. I am also not expert enough in WordPRess to know if there are other fields and tables to search through or not.

Thank you.
0
Comment
Question by:Lev Seltzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 333 total points
ID: 40321836
The first thing I would try is to edit your routing table so that all queries to http://domain.com are forwarded to http://www.domain.com. For example, in .htaccess for the www.domain.com site, put in this.
Redirect 301 / http://domain.com/

Open in new window

If that's not possible, then you will want a query like this:
UPDATE wp_posts set post_content = replace(post_content, 'http://domain.com', 'http://www.mydomain.com')

Open in new window

0
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 167 total points
ID: 40321888
I had a similar problem and used PhpMyAdmin's search feature. Search "http://www" or something similar and it will tell you how many instances where found in each table in the database. Aside from wp_posts, you will likely find instances in wp_postmeta and wp_options. Then you can use a statement like @mankowitz suggested on each table.
0
 

Author Closing Comment

by:Lev Seltzer
ID: 40321914
I managed to replace the domain name in the wp_posts, wp-postmeta and wp_options files. Thank you both for your quick and accurate replies.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question