mirror content from page within multisite

i would like to completely mirror content from a page within my multisite network. i am using the switch to blog function to find the correct site/page and then calling the content of that individual page specifically. it all works perfectly except only for logged in administrators.

i would really love to have this functionality work across the board (for public and authenticated users) not just for logged in admins.

here is my code that is working albeit only for administrators:

<?php
        global $blog_id;
        $current_blog_id = $blog_id;

        //switch to the main blog which will have an id of 2
        switch_to_blog(2);
        ?>

		<?php query_posts('page_id=2');
                if (have_posts()) : ?>
                <div>
                <?php while (have_posts()) : the_post(); ?>
                <?php echo the_content('Continue reading »'); endwhile; ?>
                </div>
                <?php endif; ?>
	<?php restore_current_blog(); ?>

thank you in advance for your help!
andrew

  • Kimberly

    Hi Andrew!

    Welcome to the WPMUDEV Community!

    Looking at the codex for your function I see that you may not be able to use this for the front end.

    ref: http://codex.wordpress.org/WPMU_Functions/switch_to_blog

    This switch is to be used for internal and admin area functions. It's too expensive a query to run on the front end.

    That's from the codex page :slight_frown:

    Let me know if I've misunderstood!

    Best,

    Kimberly

    If the above action did not result in the resolution or common end to this ticket then please feel free to come back here for comment. Just be sure you mark "Not Resolved" to re-open or we might miss it! :slight_smile: Thanks!

  • invest2s

    hi kimberly-

    interesting...

    oddly enough, i use that exact same switch to display a global navigation bar across all of my sites/blogs.

    it does work in that case

    <?php //store the current blog_id being viewed
    global $blog_id;
    $current_blog_id = $blog_id;
    
    //switch to the main blog which will have an id of 1
    switch_to_blog(1);
    ?>
                <div id="logo">
                    <a href="<?php bloginfo('siteurl') ?>" title="<?php bloginfo('name') ?>"><?php bloginfo('name') ?></a>
                </div>
                <!-- END LOGO -->
                <!-- START NAV -->
                <?php
                    $color_menu = 'black';
                    if(get_option('bl_color_dropdown') AND get_option('bl_color_dropdown') != '') $color_menu = get_option('bl_color_dropdown');
                    $options = array(
                        'theme_location' => 'nav',
                        'container' => 'div',
                        'container_id' => 'nav',
                        'menu_class' => 'level-1 ' . $color_menu,
                        'depth' => '3',
                        'fallback_cb' => null,
                        'walker' => new description_walker()
                    );
    
                    wp_nav_menu($options);
                ?>
                <!-- END NAV -->
                <?php restore_current_blog(); ?>

    it works great to display a global navigation.

    any reason you can think of why it would work and not the other example i posted initially?

    are there any other solutions to mirroring content from one network blog to another?

    thanks,
    andrew

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.