[wp-trac] [WordPress Trac] #25293: Switch_to_blog not switching the siteid

WordPress Trac noreply at wordpress.org
Thu Sep 12 09:11:21 UTC 2013


#25293: Switch_to_blog not switching the siteid
--------------------------+-----------------------------
 Reporter:  Rahe          |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Multisite     |    Version:  3.6.1
 Severity:  minor         |   Keywords:
--------------------------+-----------------------------
 When having multiple network on multisite making the following:
 {{{
 switch_to_blog(1);

 $options = get_site_option( 'my_option' );

 restore_current_blog();

 }}}
 The options retrieved are the options of the current siteid and not the
 siteid of the switched blog.
 One of the options is to make something like this :

 {{{
 global $wpdb;
 // Get the previous siteid
 $previous_site_id = $wpdb->siteid;
 $previous_blog_id = $wpdb->blogid;

 // Go to site 1
 switch_to_blog(1);

 // Set the blog siteid to 1
 $wpdb->set_blog_id( 1, 1 );

 // Get the options
 $options = get_site_option( 'my_option' );

 restore_current_blog();
 $wpdb->set_blog_id( $previous_blog_id , $previous_site_id );
 }}}

 Or
 {{{
 // Get the previous siteid
 $site_id = $wpdb->siteid;

 // Set the blog siteid to 1
 $wpdb->set_blog_id( $wpdb->blogid, 1 );

 // Get the options
 $options = get_site_option( 'my_options' );

 $wpdb->set_blog_id( $wpdb->blogid , $site_id );
 }}}

 The thing is that the switch_to_blog function does not specify the
 switched siteid on the method $wpdb->set_blog_id if the network is not the
 same as the current blog.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25293>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list