latest 5 posts using switch_to_blog loop

No, it’s retrieving the posts just fine, but you’re not storing them anywhere. Here’s your code again, with line-by-line documentation: // Set up global variables. Great global $wpdb, $blog_id, $post; // Get a list of blogs in your multisite network $blog_ids = $wpdb->get_col( “SELECT blog_id FROM $wpdb->blogs” ); // Iterate through your list of blogs … Read more

Merging multiple wp_query objects

If you just need the posts of each WP_Query object, you can do do something like this: <?php // fetch blogs here $all_posts = array() foreach($blogs as $b) { switch_to_blog($b->blog_id); $query = new WP_Query(/* your args here */); if($query->have_posts()) $all_posts = array_merge($all_posts, $query->posts); // posts are stored in the `posts` property restore_current_blog(); // FYI: this … Read more

switch_to_blog() performance considerations & alternatives

You should first read (emphasis mine): The sites in a multisite network are separate, very like the separate blogs at WordPress.com. They are not interconnected like things in other kinds of networks (even though plugins can create various kinds of interconnections between the sites). If you plan on creating sites that are strongly interconnected, that … Read more

Get Recent Posts by Date in Multisite

Since wordpress multisite uses different tables for all blogs, it is very inefficient to get all recent articles of all blogs (content aggregation) on display time since you have to query all blogs, sort the articles by date and display the ammount you need. Plugins like WordPress Post Indexer (https://premium.wpmudev.org/project/post-indexer) additional write all posts into … Read more

Sharing Dynamic Sidebars across Multisite Blogs

Unfortunately, the switch_to_blog() method isn’t going to work for this purpose. switch_to_blog() is really only a partial switch – it makes some modifications to $wpdb that help with database queries. But it’s not a complete switch in the way you might imagine. In particular, dynamic_sidebar() depends on global called $wp_registered_sidebars. This global is populated by … Read more