UPDATE 2: A lot has changed to WordPress since 2.x so I don’t recommend trying this for versions above 4.0. I can’t confirm it’s operation.
UPDATE: This also works with WP 2.7.1. If editing wp-db.php is too daunting, you can download my version, which will work as long as the prefix of your main blog is wp_.
While developing new themes for the blog, I needed a place to preview a theme that includes all the current posts, comments and categories. Thanks to a blog post from United States of Martin, I was able to set up the blog in a subdomain that only uses a different options database.
Basically the method is to tell the main blog to allow users in the slave blog to access the posts. You do that by accessing your web host’s MySQL database admin panel and entering this text as two separate queries:
INSERT INTO main_wp_usermeta (user_id, meta_key, meta_value) VALUES (1, 'slave_wp_user_level', 10)
INSERT INTO main_wp_usermeta (user_id, meta_key, meta_value) VALUES (1, 'slave_wp_capabilities', 'a:1:{s:13:"administrator";b:1;}')
where slave_wp
is the prefix of your second blog, and main_wp
is the prefix of your original blog.
The second task is to change the file /wp-includes/wp-db.php
by adding a few lines of new code. The reason I’m posting this is because even with the original instructions, I could not get it working with WordPress 2.6 for some time, even after having it work properly under 2.5.
Find this text in wp-db.php
foreach ( $this->tables as $table )
$this->$table = $this->prefix . $table;
which is likely on line 383 – 384. Immediately after this text, insert these lines:
$this->posts = 'wp_' . 'posts';
$this->users = 'wp_' . 'users';
$this->categories = 'wp_' . 'categories';
$this->post2cat = 'wp_' . 'post2cat';
$this->links = 'wp_' . 'links';
$this->postmeta = 'wp_' . 'postmeta';
$this->usermeta = 'wp_' . 'usermeta';
$this->terms = 'wp_' . 'terms';
$this->term_taxonomy = 'wp_' . 'term_taxonomy';
$this->term_relationships = 'wp_' . 'term_relationships';
$this->comments = 'wp_' . 'comments';
where wp_
is the prefix of your main blog as set up in wp-config.php
.
This immediately fixed my setup, and now I can enjoy 2 different themes, with one set of posts, comments, categories and pages.
[tags]Wordpres, 2.6, database, MySQL, blog[/tags]