Multisite with a single, shared custom post type, while retaining site URL

Small multisite setup, two very different sites, both need to access an event custom post type. I don’t want to duplicate posts (there are some plugins that “broadcast” a post to the network).

switch_to_blog(1) will get me part way there, where blog 1 is the “master” blog that contains the event data, as far as archive-style pages that list all the events. But my concern is that the URL/permalink of the event, when viewed from blog 2 will point to blog 1, and following that permalink will then take the user to the other blog, confusing the user.

Read More

Is there a solution (possibly using rewrite) that would allow an event post at //blog1/events/event1 to appear as //blog2/events/event1 when viewed from blog 2?

Related posts

2 comments

  1. There are two options:

    1. Register the CPT on blog 2 with 'show_ui' => FALSE. Hook on blog 1 into save_post and copy the data to blog 2.

      • Pro: You can search in those posts. Correct templates will be used automatically.
      • Con: Duplicated data are always a little bit … dirty.
    2. Register an endpoint with an URL scheme like the CPT on blog 1 (EP_ROOT).

      • Pro: No duplicated data.
      • Con: You have to implement the template logic manually to load the correct theme file. And search will not work.
  2. Decide which blog will contain the “data of record”, use "show_ui" => false on the other blog(s) and then modify queries that deal with that post to use the appopriate table prefix. The data will still be populated within the context of whatever blog you’re viewing (ie: site_url() will work as expected, and your templates and theme will be correct – assuming you’re using different templates and themes for different blogs), and you won’t have duplicated data anywhere.

    The downside is that in a scenario with a very large network of blogs, this might become unmanageable.

    It also means that you must have access to the “blog of record” in order to be able to enter and update the post data, unless you’re also prepared to hook into the save_post action of all the other blogs and fool them into writing the data to the other blog’s tables. You would then also need to fudge that post type’s List Tables and edit-post request as well, which is daunting to say the least.

    This solution works in the case of a piece of content that will be maintained by an administrator with access to the primary blog, but needs to be posted to or visible on other blogs on the network; it is not appropriate for content that will be created by admins/users of other blogs on the network to be shared with the other blogs on that network. For that approach, see toscho’s answer here.

Comments are closed.