Cameron
Cameron

Reputation: 28853

Share same data across two different WordPress websites

I am wanting to have the EXACT same data across two WordPress sites that are on different domains e.g. blog.company.com and blog.business.com BUT are on the same server etc. Each have their own theme but share the same data. So if I post on one the other has also has that post.

Is this possible? It's a client request, so please bear with the idea

Upvotes: 0

Views: 2333

Answers (3)

dave jesch
dave jesch

Reputation: 21

Rather than importing and exporting all the time, you can set up syndication using something like the FeedWordPress plugin.

Pick one of the sites to be the master. On the other, slave site, you can set up the syndication plugin to read all the RSS feeds from the master site every few hours. This would allow each site to have it's own comments on the posts which would not be shared.

If there are still some issues with links on the slave site pointing to the master site, you could eliminate those with a filter on the_content, changing any URL references.

Upvotes: 1

mikevoermans
mikevoermans

Reputation: 4007

I would setup 1 database for both sites. @Wyck has a concern about links stored in the database, which is valid, but a quick header.php and functions.php modification can fix that for you.

To setup the sites to use the same data, configure the wp-config.php file to use the same database information for both.

WP-CONFIG

<?php 
define('DB_NAME', 'db_name');
define('DB_USER', 'db_user');
define('DB_PASSWORD', 'db_password');

// I'm not sure if you'll need a condition or not. If your database host URL is the same or not.

$site1 = ( $_SERVER['HTTP_HOST'] != 'site1.company.com' );

if ( $site1 ) {
    // site1
    define('DB_HOST', 'external-db.company.com');

} else {
    // site2
    define('DB_HOST', 'internal-db.company.com');
    // define('DB_HOST', 'localhost');

}
?>

Header

<?php ob_start('fix_links'); ?>

Functions

<?php 
function fix_links($input) {
    // create absolute URL fixes for both domains - this only fixes the current domain. You might have to modify it being that it seems based on the subdomain as well. 
    return preg_replace('!http(s)?://(www.)?' . $_SERVER['SERVER_NAME'] . '/!', '/', $input);
}
?>

Upvotes: 2

Wyck
Wyck

Reputation: 2023

Yes it is possible put problematic, unless done right.

Any internal or hardcored linking will reflect the site where the element was created, so clicking on a post title on blog.company.com will bring you to blog.business.com or vice-versa (depending on where they were created).

I more solid solution is to use 2 databases, and exports/import and have a script that changes db values to reflect the actual connected site.

Upvotes: 0

Related Questions