A Complete Guide to Sharing Content Between Sites in a Multisite Network
I’ve been working with WordPress multisite networks for quite a while now, for more than 10 years already. It all began with client projects; then I started developing my own WordPress plugins, so over all this time, I gained some experience to share with you guys.
Below, in this guide, I’d like to show you all the possible scenarios of setting up shared content (posts, pages, custom post types, media, users, WooCommerce products, etc.) between several or all of the sub-sites of a WordPress multisite network.
You will find the explanation of how it works under the hood, but also code examples and plugin recommendations.
Basic Principles of Implementing Shared Content in Multisites
Before we dive into practical examples of syncing some specific content type between sites, let’s start with understanding a little bit of theory here.
Indexed Content vs Duplicated Content
Sharing content doesn’t necessarily mean duplicating it fully to target sub-sites. More than that, in some cases, creating duplicates doesn’t make any sense, for example, when we’re working with media files. I mean, what would you prefer better – to duplicate gigabytes of media files multiple times (to every sub-site), or simply use the original ones from one specific global media library? That’s exactly the case when using a shared index (think of it here as media files mapping) which points to the original media file on your server from any sub-site of your multisite network.
Let’s take a look at some use case examples below, for both indexed and duplicated content approaches.
| Indexed Content | Duplicated Content |
|---|---|
| As I already explained above, indexing content is super-useful when you need to have a global media library across sub-sites of your network, this feature is a part of my Multisite Shared Media Library plugin. | Centralized WooCommerce order management is one of the handy things to have in a multi-store network. So you can sync all your orders to a single site, change their status there (for example), and sync them back after that. Can be implemented with Multisite Order Sync. |
When you need to simply broadcast the posts from all the sub-sites in your network into a single site. For example, you have a sub-site for every US state, and you want to display news (or products) from all these sub-sites on the main site. The Multisite Indexer plugin allows you to implement something similar or exactly the same on your sites. However, it requires some coding knowledge to use the Network_Query class | Duplicating posts, products, etc. may have many different use cases. I had clients who were running a store for Scandinavian countries, each sub-site for a single country: Sweden, the Netherlands, etc. They used the Simple Multisite Crossposting to share the products across all sub-stores, and then translated only specific parts like descriptions, or even excluded descriptions from syncing. Sometimes you may also want to sync system content types like ACF field groups, Gravity Forms, Elementor templates, etc., which is also quite possible to achieve. |
You can also sync WordPress users between sub-sites on your multisite network; however, I can not fully relate it to either “Indexed Content” or “Duplicated Content” category, because users have a shared table in the database by default, so tables wp_users and wp_usermeta are normally used globally for every sub-site of your network. So, you never need to either duplicate or index them; all you need to do is to add a user to a specific site, that’s it.
Why you should never skip WordPress object caching when using switch_to_blog() for your indexed content
Now, let’s talk a little bit about the switch_to_blog() function. I still consider using switch_to_blog() in some scenarios as the “indexed content” approach. For example, when you only index attachment IDs, to point to a specific attachment ID of a specific sub-site.
For example:
- on “Site A”, you are using an attachment ID
123as a featured image on your blog, - however,
123is not a fully functional attachment – think of it as a placeholder, - then, in your index tables, you point this attachment to another attachment ID on a specific blog, let’s say, an attachment
234on sub-site1.
This approach allows us to hook onto wp_get_attachment_image or wp_get_attachment_url filter hooks, get data from the index, then run:
switch_to_blog( 1 );
remove_filter( 'wp_get_attachment_url', ...
$attachment_url = wp_get_attachment_url( 234 );
...The code may seem OK, but you will have quite a surprise when you add a bunch of third-party plugins to your website. In my case, it was Advanced Custom Fields.
So, what happened?
As you can see, with our filter applied, when you run the wp_get_attachment_url() function, you will have the global variables switched to another sub-site when you run wp_get_attachment_url() normally without a hook, and switch back to the original site.
Can this part be simplified with a custom function? Probably, but our store is about that in our example switch_to_blog() / restore_current_blog() instance runs only once. Maybe, in some cases, for wp_get_attachment_image(), for example, it will be run twice. But that’s it. Guess what happens with ACF? It runs these functions multiple times, like 5x times more!
Let’s calculate – assume you have 20 images on a page, then ACF will run functions that print them 5+ times each, and as a result, you will have the blog switched forth and back 100 times!
We can blame ACF, but since all this happens within a single page refresh, we can tap into the object cache easily using wp_cache_get() and wp_cache_set().
$attachment_id = 234;
$cache_key = 'wp_get_attachment_url_' . $attachment_id;
if( false === $attachment_url = wp_cache_get( $cache_key, 'my_cache' ) ) {
switch_to_blog( 1 );
remove_filter( 'wp_get_attachment_url', ...
$attachment_url = wp_get_attachment_url( $attachment_id );
...
wp_cache_set( $cache_key, $attachment_url, 'my_cache', 300 );
}
...By implementing this approach into my Multisite Shared Media Library plugin, I improved its performance tenfold.
Practical Examples of Shared Content in Multisite Networks
In the examples below, we will mostly take a look at the Duplicated Content approach, because the Indexed Content approach is much more complicated and includes in it such things as creating new database tables, mapping all the data, automatic reindexing, etc. So, basically, one tutorial is simply enough to cover it completely. But, if you wish, you can always learn from the source code of my plugins, Multisite Shared Media Library and Multisite Indexer. Though it would probably be easier just to stick to a fully functional and supported approach, I mean using the plugins as is, out of the box.
Sharing custom post types
Since sub-sites in a WordPress multisite network share the same database and file structure, sharing posts of any type between them becomes quite an easy task.
The algorithm is usually the same for any custom post type, whether it is a post or an Elementor template.
First, we need to decide how the content sharing is going to happen. For a programmatic approach, you can use one of the WordPress action hooks:
save_post– triggered every time a post gets published or updatedsave_post_{$post_type}– kind of the same, but can be triggered for a custom post type specifically.- in some plugins, there are their own hooks available, e.g.
woocommerce_update_productfor WooCommerce products.
So, in other words, content sharing will happen automatically, however, if you need some more room for customization, you can use Simple Multisite Crossposting, because it allows you to select specific target sub-sites for every post using checkboxes when editing a post:

Sharing multiple posts (or custom post types) is also supported by the plugin.
Second, we need to gather all the post data from the current site and store it in an array of something like that:
$post = get_post( $post_id );
$post_data = array(
'post_title' => $post->post_title,
'post_name' => $post->post_name,
'post_type' => $post->post_type,
'post_content' => $post->post_content,
'post_excerpt' => $post->post_excerpt,
'post_meta' => get_post_meta( $post_id ),
// etc.
);Third, we’re running the switch_to_blog() function, create (or update) a post with the same type on the target sub-site, and collect its post ID.
$target_blog_id = 5;
switch_to_blog( $target_blog_id );
// some post meta formatting
$post_meta = $post_data[ 'post_meta' ];
unset( $post_data[ 'post_meta' ] );
$new_post_id = wp_insert_post( $post_data );
if( is_wp_error( $new_post_id ) ) {
// something went wrong here
}
foreach( $post_meta as $meta_key => $meta_values ) {
foreach( $meta_values as $meta_value ) {
// wp_slash() and maybe_unserialize() will be needed in some cases
add_post_meta( $new_post_id, $meta_key, $meta_value );
}
}
...Third, we’re using restore_current_blog() function, and store a new post ID somewhere in the original post meta, so on every run of the save_post hook, we can decide whether we will create a new post or update an existing one. This is actually really what you want to keep in mind, otherwise, your sub-sites will be flooded with post copies. Though it is also not necessary to connect posts via specific metadata, you can just check their slugs, for example, something like this:
$synced_post = get_page_by_path( $post_data[ 'post_name' ], ARRAY_A, $post_data[ 'post_type' ] );
if( $synced_post ) {
$post_data[ 'ID' ] = $synced_post[ 'ID' ];
wp_update_post( $post_data );
} else {
wp_insert_post( $post_data );
}There is actually a lot more to say on this topic, for example, about syncing attachments (featured images, WooCommerce product image and gallery images, in custom fields), relationship custom fields, etc. So, if you have a question, feel free to ask in the comments below. Or, if you don’t want to bother with it, you can use Simple Multisite Crossposting, which has already been tested in countless scenarios and with all popular third-party WordPress plugins.
Centralized WooCommerce order management
As I mentioned before, order management in a centralized place can be quite handy when you’re managing multiple WooCommerce stores within a single WordPress multisite network.
For example, you have “Store M”, “Store A”, “Store B”, “Store C”; orders from stores A-C are automatically getting synced to the main store “Store M”, where they can be processed by a store manager, for example, an order status is changed from “Paid” to “Shipped”, and this status will get synced back to the original order on the original sub-store.
Syncing orders is relatively similar to syncing custom post types, the only thing you need to keep in mind is that orders are no longer a custom post type, since (I hope) you’re using HPOS for them.
First things first, we need to choose a WordPress/WooCommerce action hook on which we’re going to connect order synchronization. As you’ve probably guessed, save_post is out, and we need to use woocommerce_update_order, however, there are some nuances you need to keep in mind when you’re going to use it.
But if you’re using Multisite Order Sync for WooCommerce, all the nuances are in check there, plus you can decide whether you’d like to share orders automatically or with the help of order actions:

Second, we need to prepare an array with order data; you can do it more or less this way:
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
// include order notes
$order_data[ 'order_notes' ] = wc_get_order_notes( array( 'order_id' => $order_id ) );Third step is to use switch_to_blog() function and either create or update an order on our target site:
$target_blog_id = 5;
switch_to_blog( $target_blog_id );
$order = new WC_Order();
$order->set_currency( $order_data[ 'currency' ] );
$order->set_status( $order_data[ 'status' ] );
$order->set_customer_note( $order_data[ 'customer_note' ] );
...
$order->save();As you can see, when creating an order, I use methods of WC_Order object to add all the data to it: set_currency(), set_status(), and set_customer_note(). Of course, there are many more of them, right now, my goal is to show you the exact step-by-step process.
But what is really important to keep in mind is to preserve the information about the original order, we can store it in the order meta:
$order->update_meta_data( '_source_site_id', $source_blog_id );
$order->update_meta_data( '_source_order_id', $order_id );So, when this order meta is set, we don’t need to create a new order, but instead update an existing one.
I guess that’s pretty much it for this tutorial, guys. As you can see, the topic is quite complex, so please feel free to ask in the comments if you need any clarification.
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me