The MU forums have moved to

switch_to_blog problem (3 posts)

  1. xyzzy
    Posted 14 years ago #

    Hi, I am having a problem with switch_to_blog and restore_current_blog.

    WPMU switches to the new blog, but doesn't seem to switch back properly. My code is below. I'd like to switch to a blog, gets some posts, and switch back. The final the_content in the code should show content from the original blog's posts, but it shows the last entry gotten from the blog that's been switched to.
    commenting out setup_postdata($post); seems to help a little. the_content works, but the_title does not.

    I'm perplexed. Thanks for any help.


    global $switched;
            $lastposts = get_posts('numberposts=3');
            foreach($lastposts as $post) :
    the_content(); // this should print the_content from the original blog page/post
  2. tmoorewp
    Posted 14 years ago #

    You need to call get_posts again after you restore_current_blog(). get_posts creates a cache of the last call it had.

    Also, what is global $switched supposed to do?

  3. xyzzy
    Posted 14 years ago #

    Thanks. I copied global $switched from the sample code here:

    I appreciate your help. I'll take a closer look. Thanks.

About this Topic