Get variable from previous blog while using switch_to_blog

Your code, which I assume is in a function, should pass variables needed from the current blog. So, assuming that your code in your question is called by somefunction(), change that to pass along variables from the current blog, as in // variables from the current blog $current_blog_1 = “some value” $current_blog_2 = “another value” … Read more

Bug using wp_insert_term with switch_to_blog

Hook into ‘pre_insert_term’, $term, $taxonomy and dump the global $blog_id; to see if you’re on the right place: function wpse_inspect_blog_id( $term, $taxonomy ) { global $blog_id; var_dump( $blog_id ); exit; } function wpse_hook_inspector_blog_id() { add_filter( ‘pre_insert_term’, ‘wpse_inspect_blog_id’ ); } add_action( ‘init’, ‘wpse_hook_inspector_blog_id’ );

Multisite switch to blog

If you use switch_to_blog, that use always also restore_current_blog. The restore_current_blog function undos the last call to switch_to_blog, but only by one step, the calls are not nestable, so always call restore_current_blog before calling switch_to_blog again.