The MU forums have moved to WordPress.org

Word Press Query (5 posts)

  1. paul_fury
    Member
    Posted 14 years ago #

    I have 4 blogs now with Word Press Mu. I want to be able to query each blog from the site index page and have different loops after each one to display some entries from each blog (so 4 query calls and 4 loops).

    I'm having trouble finding how to do the query part before each loop. This is done automatically when I'm working with a page for a particular blog, but for the site index page I'll have to do it manually 4 times.

    I think I'm supposed to use wp_query() somehow, but I'm not sure. Does anyone know how to load the entry data from a particular blog before the loops?

    Thanks

  2. wpmuguru
    Member
    Posted 14 years ago #

    check the functions switch_to_blog and restore_current_blog

  3. andrea_r
    Moderator
    Posted 14 years ago #

    If you just want info from specific blogs, this works great.

    Overall though, if you want to pull all entries from all blogs on the system, there are much easier ways. :)

  4. paul_fury
    Member
    Posted 14 years ago #

    I tried the function "switch_to_blog" but it doesn't seem to be doing anything at all. I call it on the site home page, "/", and then proceed with the word press loop and it is still pulling posts from the main blog, "/", instead of the blog I switched to. The function is returning true to say that the switch was successful, yet its not pulling posts from the right blog. Why isn't this function working?

    <?php switch_to_blog(8);
    	if(have_posts()) {
    		while(have_posts()) {
    			the_post(); ?>
    			...
    		<?php }
    	}
    ?>
  5. justinph
    Member
    Posted 14 years ago #

    You have to query_posts() and start_wp(), like this:

    <?php switch_to_blog(8);
    	query_posts();
    	start_wp();
    	if(have_posts()) {
    		while(have_posts()) {
    			the_post(); ?>
    			...
    		<?php }
    	}
    ?>

About this Topic

  • Started 14 years ago by paul_fury
  • Latest reply from justinph