One install to rule them all

Edit: This post was imported from my previous site and is completely outdated. FYI.


So, as I wouldn’t shut up about in this post I’m doing this little experiment with three blogs where one should suffice. Don’t ask why. It’s an Idea I got and I refuse to let it go. After trying a lot of different methods, all of them painful, I finally managed to accumulate the wisdom of the internets to achieve my perhaps ill-concieved goal. In case you wish to travel the same perilous path; here for your benefit is a summary.

I’d like to disclose right away that almost everything in this post is lifted from this post and the comments therein. I only parrot it here with some supplementary info for the exact situation I was in.

Anyway, what I wanted was this;
I have three blogs on three separate domains. On one blog I post about tech, code, web development and so forth. On another blog I post about mental health, bipolar disorder and all that fun stuff. I’ve decided to keep these separate because not everyone interested in one of the subjects would be interested in the other. So I needed a third blog for those that actually did want both, oh and then there were some posts that really should go on all three blogs, and… Complete and utter mess. I needed some way of posting a post once, and decide what blogs it should be visible on.

Confused? Here’s a diagram.
One Install
Right. So to achieve this we need to do some hackery. To be more exact we need to have three installations of WordPress share a single set of database tables. I might as well say right away that if the word MySQL means nothing to you, this isn’t for you. Also these because these installations need to share the same database, there’s a more than decent guess to say that your domains should share a single host. Nuff warnings. Let’s roll.

Step one: Install your different WordPress blogs. Give them all unique table prefixes (you’ll have to, or the installation won’t finish). Write these prefixes down. In this example my “main” blog will have the table prefix “main_wp_” and my “slave” blog will have the prefix “slave_wp_” You now have two or more separate blogs, presumably on two or more separate domains. Create your admin account on each of them.
Wp Install

Step two: FTP to your WP-folder on the slave blog, and find the file

1
wp-includes/wp-db-php

.
Open it up in a text editor and find the line:

1
2
 foreach ( $this->tables as $table )
    $this->$table = $this->prefix . $table;

Directly below it insert:

1
2
3
4
5
6
7
8
9
10
$this->posts = 'main_wp_' . 'posts';
$this->users = 'main_wp_' . 'users';
$this->categories = 'main_wp_' . 'categories';
$this->post2cat = 'main_wp_' . 'post2cat';
$this->links = 'main_wp_' . 'links';
$this->postmeta = 'main_wp_' . 'postmeta';
$this->usermeta = 'main_wp_' . 'usermeta';
$this->terms = 'main_wp_' . 'terms';
$this->term_taxonomy = 'main_wp_' . 'term_taxonomy';
$this->term_relationships = 'main_wp_' . 'term_relationships';

…where ‘main_wp_’ is the table prefix you chose for you main blog. If it isn’t obvious; What we’re doing is to tell the slave blog to get most of its info from the main blogs database tables. “Mirroring” it so to speak. Most of of the info, but not all, so we can still run separate designs and more importantly; Separate plugins. But hold your horses. There’s more hackery to be done.

Step three:
Now it’s time to do a little(!) bit of MySql magic. What we need to do is to grant the admin user from the main blog the same privileges on the slave blog. So in whatever interface you run MySql do like so:

1
INSERT INTO main_wp_usermeta (user_id, meta_key, meta_value) VALUES (1, 'slave_wp_user_level', 10)
1
INSERT INTO main_wp_usermeta (user_id, meta_key, meta_value) VALUES (1, 'slave_wp_capabilities', 'a:1:{s:13:"administrator";b:1;}')

This should fix you up with two mirrored blogs on two different domains and with unique designs. It’s all downhill from here.

Step four: Download this plugin that will allow you to hide entries based on what categories they are in. The way I use this on my blogs is:

  • I post everything in unitedstatesofmartin.net
  • Everything I post is in one of three categories: United States(US), Sleep Furiously(SF) or Parallax Denigrate(PD).
  • ctrloptcmd.com shows posts from the US and PD categories.
  • sleepfuriously.net shows posts from the US and SF categories.
  • unitedstatesofmartin.net shows all the posts.

Hence; I can post to one, two or all of my blogs. Yippie! Now… Beware, there are some pitfalls. One of them is that the posts from the hidden categories will show up on “Recent Posts” widgets and the like. I’m looking into this. Also I’m fairly certain that more stuff will jump up and bite me in the ass, and If so I’ll keep you posted.

Possibly related posts:

  1. Experiment concluded If you read this post, or maybe the FAQ on...
  2. Quickly whitelist sites in Kill-Flash Is it hypocritical of me to write about a Flash...
  3. Crudmuffins Update: Bug squashed. So buried deep in the archives there...
  4. Better (AS3) imports in TextMate Summary: In which Martin has concocted a hack to make...
  5. The blog is dead. Long live the blog! If you managed to visit this blog in the 10...

9 Comments

  1. Wes G
    Posted June 10, 2008 at 02:00 | Link

    Hello! This is a great post, as it does exactly what I was looking to do. I want to add something that I noticed with your solution.

    The apostrophes in your code need to be replaced in order for WordPress to use them. It sounds weird, yes, but my installation only worked after I did a find and replace.

    Good work!

  2. Martin
    Posted June 10, 2008 at 09:42 | Link

    That’s odd.
    I seem to remember I posted this verbatim from the code I used. Then again; It’s been a while. :)

    Good to hear you found it useful and fixed the apostrophe issue.

  3. Posted July 16, 2008 at 13:48 | Link

    Well, that’s a sleek solutions, to say the least! Great job. It sure takes a lot of trouble off my head. :)

    I’ll make sure to future it these days on my blog!

  4. Posted July 16, 2008 at 14:00 | Link

    oh btw what can I expect from this method related to duplicate content penalty? Or in this case it doesn’t count?

  5. Martin
    Posted July 19, 2008 at 15:45 | Link

    I must confess I’m not really sure if this would incur some sort of penalty from google. It might… If SEO is a huge concern you might want to research a bit before trying this experiment.

  6. Mario
    Posted July 29, 2008 at 20:18 | Link

    AAHHHHRRRGG!! I did everything as you said but it does not work.. :( Anyway…this is not even what I am trying to achieve but could have helped..what I am really trying to achieve is having one user dedicated admin installation with custom fields and all modified template pages sitting under a subdomain and my admin, full-capable admin installation wherever (on the main domain probably) while BOTH use the same tables and modify ONE website..thanks for the post though..

  7. Wes G
    Posted August 15, 2008 at 23:09 | Link

    Hey Martin, any thoughts about getting this to work again with WP 2.6?

  8. Wes G
    Posted August 16, 2008 at 00:06 | Link

    I figured it out, it was the same text only in a position farther down the file.

  9. jc min
    Posted October 3, 2008 at 09:14 | Link

    Would this allow me to be logged on to both blogs at the same time? or do i still need to find away to pass cookies as i have tryed just about everything.

    currently i have two blogs using different prefix, one database, same userbase (automatic)

    now just gotta pass cookies ><

One Trackback

  1. [...] 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 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*