• Gilad

    (@virtualgilad)


    Greetings.

    The below was posted to the troubleshooting forum more than 5 months ago. Another member showed interest in the same topic, but no suggested solutions were ever offered. I’m reposting here as I still need to investigate this and do not yet have enough knowledge about WP (or MySQL) inner workings.

    I would like to power two (or more, perhaps) different WordPress sites from the same data. Note that I am not looking to drive multiple sites from the same database in which each site has it’s own tables in a common database.

    Rather, I want these two sites (or more) to use the same data (same posts, pages, etc), without having to copy/paste the data between multiple blogs. So, these sites will actually hit the exact same tables when they respond to end user requests.

    The idea, for those who may be curious, is to have multiple presentations/formats of the same data. I’ll use my current project to demonstrate:

    1. Primary site is the main place the author will post to (hopefully, the only place). This site will have a fairly traditional blog look. This site will contain a very wide array of topics (actually sub-topics, as they are all related).
    2. Secondary site will have a less bloggy theme and will show a very small subset of posts/pages/etc from the primary site. Most likely, the secondary site will not show any comments, though it may report the number of comments that have been posted to the post on the primary site.

    I’d like the process of “copying” posts between the sites to be as automatic as possible – So repeated customizations to RSS embeds and similar hacks will not work. Ideally, the author can mark posts that are to appear on both sites with a custom field (or category) that the secondary site theme will check for.

    The purpose of the secondary site is to serve as a teaser marketing piece, while the primary site is the meaty destination.
    My questions:

    1. Is this safe to do?
    2. If “no”, why not?
    3. If “yes”, what is the best approach?
    4. Also if “yes”, is there a safe maximum number of sites to deploy in this fashion?

    Apologies for the lack of links – These sites only exist on my dev box for now…

    TIA!
    Gilad

Viewing 5 replies - 1 through 5 (of 5 total)
  • 1. Yes, this is safe to do.
    2. See above.
    3. You’ll need a little bit of custom coding to make this work …

    It’s possible to have multiple sites run off the same database (pulling the same content from the same tables) without having to copy anything back and forth. The problem comes when you want different themes for each site. The blog theme is actually set in the wp_options table, so if your sites are all pulling from the same database they will all use the same theme.

    There are several theme-switching plugins available already that you can look into using. That would be the easiest solution for you assuming you don’t want to spend any time or budget on developing custom functionality.

    Here are a couple of theme switching plugins:

    1. https://www.ads-software.com/extend/plugins/nkthemeswitch/
    2. https://www.ads-software.com/extend/plugins/theme-switcher/

    The alternative is to use a modification of a system like WP Hive. This plugin allows you to install multiple blogs on the same database using different tables – the plugin actually handles which blog points to which table. This could be modified to give you a separate options table for each blog while leaving the rest of the tables alone. This would require a significant amount of custom coding, so I recommend either contacting a developer (I can recommend a few) or dropping a request on https://jobs.wordpress.net. In either case, this route would probably cost you money.

    4. The maximum number of blogs depends entirely on your server setup and traffic. I run 10 blogs off the same database with no trouble at all.

    Thread Starter Gilad

    (@virtualgilad)

    Wonderful! Thanks for all the detail!

    I believe I will explore the separate wp_options tables approach. I’m still rather new to WP, so I don’t know yet how to account for all the factors (like where I need to touch code that will make the multiple wp-options tables solution actually work, and work safely).

    If you have any further hints (favorite articles, sites, books, etc), that would appreciated. Meanwhile, I’ll start looking through the code for references to this table.

    I appreciate your warning regarding the complexity of the tasks. PHP is a somewhat new language to me, but I’m very comfortable with the “learn by doing” approach (as has been the case with other sites I now have).

    And speaking of other sites… Please forgive the poor forum ettiquette, but I’d like to take advantage of your apparent expertise: I’m having an issue on another site with an $author_base mod. The request for help is at https://www.ads-software.com/support/topic/282668, and to my surprise, there has been no feedback thus far. I’ll check there for any replies you might have to share, in case you have the time.

    Thanks again for the detailed response!
    Gilad

    One alternative you might want to look into is the set of functions that WordPress uses to determine the active template. First, WordPress checks for the template name and queries the database to see what template is in use.

    The actual function is:

    function get_template() {
         return apply_filters('template', get_option('template'));
    }

    This checks to see what the active template is in the database. You can create a filter to replace whatever value is returned. Here’s an off-the-top-of-my-head example:

    function switch_template() {
         add_filter('template', 'whatever-you-want-it-to-be');
    }
    add_action('init','switch_template');

    Like I said, this is off the top of my head, but it should replace the template with whatever you set programatically. You can set your own conditions on this as well to pick which template is being used.

    Just one idea among the many you might want to look into. I’d recommend using some kind of phpxref tool to search for different functions so you can see what the get_template() and get_template_directory() functions look like.

    Thread Starter Gilad

    (@virtualgilad)

    Once again, THANKS!

    I feel far better armed to tackle this now than I did before! I really appreciate the time you’ve dedicated to support my efforts!

    I’ll report back here when I have something to share.

    Thanks again!
    Gilad

    Gilad,

    Let me amend the code I sent earlier (now that I’ve had more time to think about it). You actually need two functions:

    function switch_template() {
         add_filter('template', 'my_template');
    }
    add_action('init','switch_template');
    
    function my_template() {
         $my_template = 'My_Template_Name';
         return $my_template;
    }

    This should allow you to programatically override what’s set in the database.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Multiple WP sites from same DATA TABLES (not just DB)’ is closed to new replies.