Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
I'll add more to this post: I'm not familiar with querying posts from the database. –  Gregory Schultz Feb 25 '12 at 2:27
add comment

2 Answers

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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