Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

(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.

share|improve this question

2 Answers 2

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.
share|improve this answer
    
Thanks @Phantasmix but this looks like it pushes content or pulls content manually. What I'm looking for is basically the ability to intercept a URL request on one site and pull content from another site. –  Chris Haas Oct 23 '12 at 12:47

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
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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