• I’m trying to setup different websites depending on the country, but using the same database.

    This is what I want to achieve:

    -I have a main website, domain.com with all the posts from every country
    -Want to set up different websites for each country, filtering by a country taxonomie. For example
    domain.co.uk – show only the posts from uk
    domain.com.au – show only the posts from australia

    I’m not having trouble with the filtering. The problem is how to set up the site url and template path for each site to work.

    Is it possible to do this from a config file and load the vars on the fly? Or maybe via .htaccess?

    Would love to hear what options do I have here, I guess there’re several different ways to achieve this.

    Thanks in advance!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jrenzi

    (@jrenzi)

    Just to be clear, I would be doing a new wordpress installation for each site, but all sharing the same database.

    Anyone please?

    Thread Starter jrenzi

    (@jrenzi)

    Or maybe there’s a way to map each country version to a domain? For example https://www.domain.com/uk to https://www.domain.co.uk.

    But still I’d like to use a different template for each country. Don’t know, just throwing ideas…

    this is how you do it

    add_filter( 'site_url', 'filter_site_url','high' );
    add_filter( 'home_url', 'filter_site_url','high' );
    add_filter( 'admin_url', 'filter_site_url','high' );
    add_filter( 'post_link', 'filter_site_url','high' );
    add_filter( 'page_link', 'filter_site_url','high' );
    add_filter( 'post_type_link', 'filter_site_url','high' );
    add_filter( 'attachment_link', 'filter_site_url','high' );
    add_filter( 'category_link', 'filter_site_url','high' );
    function filter_site_url($url)
    {
    $url = str_replace('www.','subdomain.',$url);
    return $url;
    }

    the code above will replace the domain url with a subdomain url and will trick wordpress to use the main domain name but with a subdomain url, this is implemented here on an accommodation website that uses wordpress as the main cms betabookings.com

    Thread Starter jrenzi

    (@jrenzi)

    Thanks, but I don’t want to use subdomains but full domains.

    BTW, I can’t see the example working in that site

    i didn’t try it for a different domain name, but i think it will work because if you change the domain name you will be able to see the index page which will make this code work

    replace the function below

    function filter_site_url($url)
    {
    $url = str_replace('www.domain.com','www.newdomain.com',$url);
    return $url;
    }

    by the way, https://www.betabookings.com and fb.betabookings.com use the same database ??

    Thread Starter jrenzi

    (@jrenzi)

    That’s cool! Will try it.

    So how do I use this? Do I place this code in functions.php?

    yes, place it in your functions.php, it should work fine for a new domain

    Thread Starter jrenzi

    (@jrenzi)

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Using same database for different domains’ is closed to new replies.