WP multisite restore_current_blog() Not Working

I am using WordPress 3.8.3 and i am using it for multisite.

WordPress multisite switch_to_blog() and restore_current_blog() functions works well for single query but in loop restore_current_blog() function is not working.

Read More

Any one have idea how I will fix it?

Thank You.

Related posts

Leave a Reply

1 comment

  1. You need to use restore_current_blog() for each instance of switch_to_blog(). I just ran into this bug myself.

    Does not work

    for [each multi site instance] {
      switch_to_blog()
      // logic
    }
    restore_current_blog();
    

    Works

    for [each multi site instance] {
      switch_to_blog();
      // logic
      restore_current_blog();
    }
    

    It appears that the switch_to_blog() function does not store the original blog globally so it can be restored outside of a multiple loop. I will be investigating to see if this can be fixed somewhat easily and will try to contribute it to core.