• kapils003

    (@kapils003)


    Is there any way to get all posts,categories etc from multiple blogs in multisite because switch_to_blog is working for only one blog_id at a time

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Thread Starter kapils003

    (@kapils003)

    i don’t wanna use any plugin i just want to do it through switch_to_blog() function …. but loop is not working …

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I never understand people who don’t want to use plugins… But since you don’t, perhaps you should review their code to see HOW they handled that exact issue instead of struggling to reinvent a wheel ??

    The beauty of open source: You can read their code and learn from it.

    Thread Starter kapils003

    (@kapils003)

    i reinvented the wheel mam because everything i am getting was fine when i have to switch only one blog id. When it comes to switch multiple blog_ids at same time then problem comes with switch_to_blog() function because foreach loop iteration is not working with switch function..now i don’t want to change code for whole site and use other functions. if you have an idea of how to do it right then i will really thankfull to you.

    global $wpdb;
            $query = "
            SELECT blog_id
            FROM $wpdb->blogs
            WHERE site_id = %d
            AND public   = '1'
            AND archived = '0'
            AND mature   = '0'
            AND spam     = '0'
            AND deleted  = '0'
            AND blog_id != '1'
        ORDER BY blog_id ASC";
        $blogs = $wpdb->get_col( $wpdb->prepare( $query, $wpdb->siteid) );
        foreach ($blogs  as $blog){
        switch_to_blog($blog['blog_id']);
        code //
         restore_current_blog();
        }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem switching multiple blogs in Multisite’ is closed to new replies.