Solutions to repost categories into multisite blogs?

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.

Read More

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.

Related posts

Leave a Reply

1 comment

  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