I have a WordPress network install and I'm looking for a way to display all posts on the front page. I'm using switch_to_blog and it works but it only works for showing one blog. Does switch_to_blog support multiple blogs? If not, what's the best way to show posts from multiple blogs without a plugin? I tried the sitewide plugin and I kept getting errors.

Thanks, Gregory S.

  • I'll add more to this post: I'm not familiar with querying posts from the database. Commented Feb 25, 2012 at 2:27

2 Answers 2


switch_to_blog does not support switching to multiple blogs at the same time, instead if you want to list all posts in a network, you'll need to loop through each blog, using switch_to_blog and restore_current_blog, saving each post in each site into a PHP array, then finally displaying every post in that array once it contains all the posts.

Note that this will require you to understand PHP variables, arrays, and WP_Query, the first two of which you can find in any basic PHP tutorial, and the last you can find a good set of slides by Nacin You don't know Query


switch_to_blog() switches to only one blog at a time, so could loop through all the blogs you're interested in and call switch_to_blog( $blog_id )restore_current_blog() for each one.

If instead you want to do a mega-query for all the latest posts across all blogs, I think you need a plugin. It's possible automattic publishes one since they do something similar on WordPress.com.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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