1

I have done a search on this topic but was unable to find a solution to this specific question involving wordpress multisite.

I currently have a wordpress network where domain.com is our main site and then each site has been localized with country code domains and also specific country services.

Eg: Main domain.com - Australia domain.com.au - UK domain.co.uk etc

In the back end it is set up as sub directories, domain.com, domain.com/au etc.

What I am looking to do is to set up categories on the main site eg:

Gallery - Australia - UK etc

When I tick the box for "Australia" it would automatically repost all posts from the sub category "Australia" into configure/set matching categories?

Is there a plugin/solution to this qeury? Have read a lot of articles but were only meant for single site installations.

  • To clarify: You want a post on domain.com to also appear on domain.com.au if the Australia category is selected? – Pat J Mar 20 '14 at 20:11
  • Hi Pat. Yes. Post on domain.com and it would auto distribute the same post to which ever the category is set to. – Lilap Mar 21 '14 at 0:08
1
add_filter( 'the_posts', 'wpse138563_add_posts' );
function wpse138563_add_posts( $posts ) {
    if( ! is_multisite() ) {
        // if we're not using Multisite, bail
        return;
    }
    if( is_main_site() ) {
        // if we're in the root site, bail
        return;
    }
    $country = get_bloginfo( 'name' );
    // This assumes that the categories in your main site
    // have the same names as the country sites do
    if( $query->is_main_query() ) {
        // alter the main query
        switch_to_blog( BLOG_ID_CURRENT_SITE );
        $category = get_cat_ID( $country );

        // get the posts with the appropriate category
        $args = array(
            'category' => $category,
        );
        $more_posts = get_posts( $args );
        $posts = array_merge( $posts, $more_posts );

        restore_current_blog();
    }
    return $posts;
}

Untested. Hopefully this works, or at least provides you a starting point.

Caveat: The categories in your root site must have the same name as the site names of your subsites for this to work. ie, to have a post show up in a site named "Australia", your category on domain.com must be named "Australia".

References

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.