switch_to_blog($blog_id); still writing to main blog
switch_to_blog($blog_id); still writing to main blog
switch_to_blog($blog_id); still writing to main 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
You are looping through the posts queried before your switch_to_blog() statement. Your code appears to be from a page template which is executed AFTER the main query has run. To be clear, the main query is run before the template code is executed. Switching to another site after that does not update the query, therefore … Read more
How to get tags from different blog?
switch_to_blog() + do_action(‘generate_footer’) not working in multisite
Just keep in mind this is only going to get you the image ID, but it should do the trick… does in my circumstance at least. // switch to the correct blog switch_to_blog( $site -> blog_id ); // pull in our db global global $wpdb; // get the image ID $_image_id = $wpdb -> get_col( … Read more
Edit: You have an extra underscore in your table name, it becomes wp__posts in your case. Better use like how I have shown below 🙂 First, use table names like the following and try var_dump to see if it returns NULL. In case the Post ID doesn’t exist, $product will be NULL, which only var_dump … Read more
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’ );
Short answer but… get_blogaddress_by_name or get_blogaddress_by_id look to me like what you need. Both return the full blog URL.
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.