I want to run 2 wordpress sites, one.site.com and two.site.com from the same database. Everything remains the same except for the theme.
- one.site.com – Existing site
- two.site.com – Should use one.site.com’s database except for the
theme
Is there any way this can be done ?
Since theme details are stored in wp_options
table is it possible for two.site.com to use it to display a different theme ? Say duplicating that table and making two.site.com use it ?
I appreciate any help.
EDIT:
Both the sites do not have any plugins.
The solution below did the job for me,
Install 2 WordPress sites on a single database.
Create new table in your database. Call it
wp_options2
and copy everything from wp_options into this new tableIn second install go to wp-config.php, and before
if (!defined('ABSPATH'))
adddefine( 'M7_OPTIONS_TABLE', 'wp_options2');
In second install go to wp-includes/wp-db.php on line 1009 and add code:
These codes should be added in
public function tables
function, beforeif (isset( $tables['users']) && defined('CUSTOM_USER_TABLE')))
I found this solution here, https://wordpress.stackexchange.com/questions/84313/how-to-run-two-wordpress-blogs-with-different-themes-and-with-single-database-an#answer-175494
Since we use the same database, links will be same on both the sites. I had a lot of images linked and I removed them using
You can run two sites from a single database but not from the same set of database tables as the stored data includes the site’s domain name.
There are two values in the options table: siteurl and home which are used. Using the same options table won’t work, even if you update options forcefully for each php run.
So you would need to use two databases.
EDIT:
My advice is to replicate base and run both sites on different databases.
This could probably be accomplished by using wildcard subdomains (https://codex.wordpress.org/Configuring_Wildcard_Subdomains).
It may be a little hacky, but you’d have to test the condition of your subdomain (maybe in wp-config.php?) and set the theme in the database (http://www.inmotionhosting.com/support/edu/wordpress/change-theme-in-db).
The only problem I could see with this is that your functions.php can change WP functionality, so a Parent theme with two Child Themes is probably a good idea(https://codex.wordpress.org/Child_Themes).
There is a lot of jiggery hackery regarding this question, but I think there’s a fairly simple solution. First, ensure that both of your 2 sites have these hardcoded in wp-config.php:
These will help each site “override” whatever the database setting is for the URLs.
Next, decide which site is the MASTER site where you are going to be publishing new blog posts, making edits to site data, and such. On that site, activate the theme you want to use.
Now, go to your SLAVE site (I’m using these terms loosely) and delete that theme via SFTP, and upload whichever other theme you want to use on that site. Then, hardcode it like this:
In this way, the SLAVE site tries to find the correct theme from wp_options that is activated on the MASTER site but you deleted it already, so it reverts to using the default theme as defined in wp-config.php
Going forward, do not mess with site settings/plugins/etc on the SLAVE site, and make any changes to the design of your SLAVE site using the theme files only (like a static theme). Obviously if you are using a bloated theme and page builder type of situation that need MySQL, this isn’t going to work…
Note: you may need to visit
/wp-admin/themes.php
on your SLAVE site at least once, to “force” WordPress to load the hardcoded theme.If anyone is interested, SlickStack supports this approach.
Duplicate of https://wordpress.stackexchange.com/q/65560/wp-multisite-load-content-from-site-x-on-site-y
One might argue that using WP multisite-network functionality and adding a couple of documented API calls to ones theme could be a cleaner solution than manually modifying the database schema and messing with how WP access it.