Two WordPress Sites, Two Themes, One Database

Posted on 2012-08-27
Last Modified: 2012-08-28
I posted this over on the WP forums to no avail. I also see a similar question here in March, but I don't want that solution, because it is essentially two databases:  Here goes:

We are renovating our website. it is a complete over haul of the UI, wrapper, theme etc. we are doing this in a different domain-dev.url and /home/devmhydomain/ folder on the linux server. So, it's on the same box and can access the same MYSQL.

I am trying to work out a strategy that will allow us to proceed with the WordPress development on the new site, but continue to use the same database, so that the blog archives will be up-to-date when we go live on the new site. I am pasting below a final "solution" posted on a six-year old thread on the Word Press Forums to see what anyone  thinks about it.

"Two Sites, Two Themes, One Database"

it seems a bit dicey... but it could work.

My developer says another option would be to install the new WP site on our site where we are doing all the development, give the new WP have it's own new database and then export, migrate and import the old database into the new database. The problem is: any posts in the interim between then and when we actually go live, will not have been migrated (could be a month or more of posts)

Another strategy could be to develop the new theme on the old site. then when we go live I just copy the blog folder overand just change the themes to make the one that is in development the "live" theme. The top level domain URL will not change, so it should work..

My problem is that I have a different structure for the paths to CSS and JS files... I'm not sure that's a big issue because on the old site I could set up a /assets/css /assets/js to match the new site and then the new theme would point to those instead of the current top level /css and /js folders... This seems safest... I think you can develop new themes in WP with private url's right?

OR: i could try this thing below where they suggest duplicating the wp_options table and give it a new prefix and the new site/dev domain, which will be up and running with the same database/archives.. then if someone posts on the old site, it automatically begins appearing on the new site.

my main developer is worried and cautions: "We have to be careful. I don't know what will happen if you install a new version of Word Press on the dev site and point to the same database, if it updates the database in some way that will break the old Word press installation, then the blog will die on the old site."

That's his worry and it's probably a good one.

I would appreciate any advice on "best strategy" here. I really would like to use the same dBase if at all possible. As all the migration, export, import and missing interim posts looks like pain.

Old thread which was closed six years ago:



someone wrote:

I've done this before, having 6 websites shoot out content from the same database.

It's easy enough to do. Upload WP into both directories. Make sure they have the identical wp-config.php file.

In the second sites directory do the following:
In the wp-settings.php file change the options database value to something like this:

// Table names
$wpdb->posts = $table_prefix . 'posts';
$wpdb->users = $table_prefix . 'users';
$wpdb->categories = $table_prefix . 'categories';
$wpdb->post2cat = $table_prefix . 'post2cat';
$wpdb->comments = $table_prefix . 'comments';
$wpdb->links = $table_prefix . 'links';
$wpdb->linkcategories = $table_prefix . 'linkcategories';
$wpdb->options = 'YOURNEWPREFIX_options';
$wpdb->postmeta = $table_prefix . 'postmeta';
$wpdb->usermeta = $table_prefix . 'usermeta';

$wpdb->prefix = $table_prefix;

See how I've removed $table_prefix . in the options line?
Instead of YOURNEWPREFIX put something like 'site2' or whatever you want.

Then, in PHPmyAdmin duplicate the wp_options table, and rename one of the them to be YOURNEWPREFIX_options, so if you chose 'site2', it would be 'site2_options'.

Bingo. Edit the information in the 'site2_options' table to refelct the correct information for your second site and you will be on your way.


so i am thinking to try this approach,  if I

a) use the exact same version of wordPress in both domains
b) do not do any posting from the new domain,
c) just stick to developing the theme.

will it work? That solution is six years old so i don't know whether a single installation of WordPress now has many more dependencies in the database beyond just the wp_options table.

Any thoughts?
Question by:Sivakatirswami
    LVL 70

    Expert Comment

    by:Jason C. Levine
    You can easily point two installations of WordPress to one database but two themes with different file paths is not going to work all that well.

    The solution posted above regarding the wp_options table might work but it will also affect plugins and permalinks and some other stuff.  Assuming you go very slow and test at each step, I could see it working.

    I would actually consider a different path: just federate or replicate the wp_posts table between the two WP databases.  That will keep the content synced and allow complete customization of all other WP elements.

    Author Comment

    Aloha, Jason (I live in Hawaii)

    I like your proposal, but it's a bit over my head.

    "just federate or replicate the wp_posts table between the two WP databases."

    1. How is this done? I'm not a MySql expert other than being able write queries, and use ALTER to change some fields, my knowledge ends about there.

    2. would this mean that we have to post the same article twice each time it is done? (my users will never do that!)
    LVL 70

    Accepted Solution

    Aloha, Jason (I live in Hawaii)


    How is this done?

    Talk to your developer if you aren't familiar with the more arcane functions of mysql.

    Basically, the Federated storage engine allows to have a table synchronized across MySQL databases and the data is live.  So changes to the table in site A instantly update in site B and vice-versa.  The end result is two wordpress sites with two different databases but the content table (wp-posts) is shared between them.

    Author Closing Comment

    Oh wow... better than mangos and fromage blanc from our own trees and cows! We will try it.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and Log…
    The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now