Multisite, sharing content by URL

I have a network of two sites, A.example.com and B.example.com. I’d like it so that if I create a page on A with a permalink of /Widgets I can access it on B using the same relative permalink but without having to actually create the content on B. (One site has user profiles that we’d like to continue to manage on a single site but expose on the other site, too.) Site B would still “look” like B but the content would come from A.

I was thinking of hooking into init but didn’t really know what to do and the documentation isn’t really helpful. Or would it make more sense to hook into pre_get_posts and just change the table prefix that I’m querying?

Read More

(I know MS isn’t intended for this model and that I’ll have to handle repercussions like links within the content but that’s not a big deal.)

Thanks

[EDIT]

Sorry, /Widget was a bad name probably, these aren’t WordPress Widgets, just regular posts.

Related posts

Leave a Reply

2 comments

  1. Hope I understand you correctly. Not sure if your /Widgets content would be actual widgets, or just posts/pages, but I’ve been using this plugin for duplicating content between sites on a multisite network: http://wordpress.org/extend/plugins/diamond-multisite-widgets/

    Use the “Broadcast on the network” feature. You can select on which sites you’d like to duplicate the content. 2 caveats:

    1. If you create a post on site A, broadcast it, then revise it with “broadcast” featured turned on again, it’ll create a 2nd post on site B. In other words, you can’t broadcast updates. Once the post is copied, it’s totally separate from the original.
    2. Your broadcasted/copied post will be added to “Uncategorized” automatically. Then you go into the 2nd site and assign proper categories to the post.
  2. I ended up going with pre_get_posts.

    add_action('pre_get_posts', 'custom__pre_get_posts');
    
    function custom__pre_get_posts($query){
        //Get access to global variables
        global $blog_id;
        global $wp_query;
    
        //Make sure we're not in admin, only run on the main query and don't run on our primary site
        if($query->is_admin || !$query->is_main_query() || $blog_id===1){
          return;
        }
    
        //Try running the query
        $test_obj = $query->get_queried_object();
    
        //If we didn't get a result then the page wasn't found
        if(!$test_obj){
          //Switch to the main site
          switch_to_blog(1);
          //Reset the query using the same args as the original (the previous reset changes $wpdb)
          $wp_query = new WP_Query($query->query_vars);
          //Re-query the object again. We might need to perform more sanity checks here
          $test_obj = $query->get_queried_object();
          //Switch back to our current site
          restore_current_blog();
          //
        }else{
          //This is a normal query for a page that exists, we don't need to do anything
        }
    }