WP Multisite: load content from site X on site Y

You can just use the function switch_to_blog before running the WP_Query on your post_type “projects”.

Switch the current blog to a different blog. switch_to_blog(), is
useful if you need to pull posts or other information from other
blogs.

Sounds like this is what you want. So lets say you have your content on the main_site. Run this on the mobilesite:

// Get current blog_id
global $blog_id;

// Run this code if on mobilesite
// Change from blog_id 2 if another id
if( $blog_id == 2 ) {

    // Switch to the main_site
    switch_to_blog(1);

        // Get from projects and all of the posts
        $args = array(
            'post_type'  => 'projects',
            'posts_per_page' => -1
        );

        // The Query
        $the_query = new WP_Query( $args );

        // The Loop
        while ( $the_query->have_posts() ) :
            $the_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        endwhile;

        // Restore original Query & Post Data
        wp_reset_query();

    // Switch back to mobilesite
    restore_current_blog();
}

Leave a Comment