0

I'm trying to get posts from the main site to sub site using a query but It didn't work

SITES : MAIN SITE ID#1 - Post1 - Post 2

SUBSITE ID#2 I need to get the Above posts here - Post1 and Post2

2
1

I use this codes to loop over the posts in the Main site:

<?php
$sites = wp_get_sites();
foreach($sites as $site) :
    // Only subsites
        // Connect to new multisite
        switch_to_blog($site['blog_id']);
        $case_args = array(
            'post_type'        => 'downloads',
            'posts_per_page'   => 1,
            'orderby'          => 'date',
            'order'            => 'DESC',
            );
        $latest_cases = new WP_Query($case_args);
        if ( $latest_cases->have_posts() ) : ?>

<?php the_title(); ?>

<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query();
// Quit multisite connection
restore_current_blog();
endforeach; 
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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