JayminKapish
Subscribe to jayminkapish RSS Friend Jaymin Patel on Facebook Follow Jaymin Patel on Twitter

« Go to home page

WordPress MU: get posts/pages from different blogs under same installation

How can you create a loop to get posts/pages from different blogs under same MU installation?

1) you can use switch_to_blog function
http://codex.wordpress.org/WPMU_Functions/switch_to_blog

2) create wordpress loop (this will get posts from the blog you just switched)

3) do whatever you want with data

4) restore current blog you are on so everything runs after this code go to the blog it supposed to
http://codex.wordpress.org/WPMU_Functions/restore_current_blog

switch_to_blog(1); // we are switching to blog id # 1
query_posts('showposts=5'); //this would get top 5 posts from blog id # 1. you can change the loop to the get posts from x category
if (have_posts()) :
while (have_posts()) : the_post();
//do whatever you want with data here...
endwhile;
endif;
restore_current_blog();


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


About

Wordpress Work

Plugins I like

Recent Posts

Wordpress News

Blogroll

Connect

I am excited about