switch_to_blog
changes values of global variables (as you can see here: https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-includes/ms-blogs.php#L801). It doesn’t matter if you call it in function or not – these variables will get changed.
So yes – you always have to call restore_current_blog
when you’ve done all you wanted with the switched blog.
Otherwise these variables will stay changed (so wpdb
will query wrong tables and so on)
Related Posts:
- Get menu object from theme_location
- Prevent “main” WPMU site_url() being returned in functions
- Implementing DNS Prefetching with WordPress
- How to include one class/instance without using global variables
- syntax for remove_filter in parent theme with class
- Different functions file for each site in multisite installation?
- Delete pages and Create default pages for all new network sites
- Multisite, either change the name of sample-page or create new page
- Loop (iterate) through Multi-Site sub-sites (blogs)?
- Global functions on WPMU
- Run function when WordPress new multisite is created or ACF field is updated
- Conditional Gravity Forms filter in WordPress Multisite
- Multisite Ajax serialize return error [object Object]
- Creating new blog on multisite programatically without hacks?
- How to get correct URLs in network wide menu (Multisite)?
- Multisite 404 on pages – rewrite error breaks database
- Has is_archived() for sites in a multisite changed with WP 4.7?
- Function that outputs second theme url
- dynamic site link for future migration in echo do_shortcode()
- wp_get_attachment_image_src returns image on main domain, false on subdomain
- functions.php return custom text
- Dashboard blocker on network multisite for specific user roles
- Members only function, but allow account activation [solved]
- Child theme, how to cut the functions.php file into several classes?
- Pass an argument into a function to extract from array
- Competing Login Redirects – Need to be Combined?
- Adding a class to the body of an inactive site using multisite
- Run function from parent on child site
- How to save custom made object in an array in a post meta field
- Ads Only at one website inside multisite network – code error
- Different ads on every website on multisite environment
- How can I modify or filter this variable in an existing class? (Mai Theme)
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- Is it possible to rename a post format?
- How to paginate the get_users function?
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Child theme – overriding add_image_size by a child theme [duplicate]
- Check if has any sidebar active on current page
- Compare post levels and user levels wishlist member
- Change ul class=”children” for wp_list_pages?
- Target a certain page within wordpress backend (admin) i.e. Pages > About
- Set default options for inserting media
- Remove tag on my RSS Feed
- Automated mark posts as featured every day
- Session is not starting
- Child Theme Not Overriding Parent Theme
- Trouble using antispambot()
- Polylang: pll_e() & pll__() on functions.php, doesn’t work
- Post Pagination Showing Same Posts Every Page
- WP_Remote_Get Not working
- Debugging with functions.php
- Load .txt file for login_message in wp-login.php
- Php function 301 redirect
- Function only on a specific page
- Logout Shortcode URL
- Add Custom Background Properties to Customizer
- What is the correct way of updating wordpress options
- WordPress functions.php – Execute plugin specific user online
- Skeleton Child Theme Add Icon Bar to Header Flex Grid
- error in getting post id
- Trying to register script in footer
- register_sidebar_widget is deprecated since version 2.8! Use wp_register_sidebar_widget() instead
- Require file in functions from theme directory using PHP
- Shotcode argument issues
- Remove Custuomize Sections
- (Woocommerce) Order by price when entering specific category
- Adding an option to a shortcode
- Get urls of images in a gallery?
- How can I show immediate and/or parents in a title?
- Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
- Best way to disable sidebars on posts (only)?
- How to override this theme function in child theme
- Enqueueing scripts selectively & activation where needed
- Overwriting TwentyTwelve template file with child theme template, but lower in the hierarchy
- Using One Function To Create Two Different Shortcodes
- How to Not Show posts on Category page?
- Is it possible to load recaptcha script only in url with fragment identifier (#)?
- page shows short code not output
- Scheduled post delete – can’t pass the cron arguments
- Prevent function from triggering on current page
- Assign IDs to headings in ACF using functions.php
- Multiple Notifications SetInterval
- Child Theme not loading multiple stylesheets
- How To Show Shortcodes In WordPress Custom Fields?
- Post date on Custom field
- Fatal error: Call to undefined function add_action() – an untouched problem
- Author info does not show up when author has no posts
- How to wp_enqueue_script with html?
- use system script advertising in wordpress multisite
- Add custom class to all URLs on entire site
- Is it possible to change parameters of Parent theme function in the Child theme?
- Unregistering custom tinymce plugin?
- Combining wp_current_user() and a variable
- Init hook for header send
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- site_url is not honoring scheme
- new to javascript – using in instead of functions.php, not loading correctly
- Remove Disqus JavaScript from homepage
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- How to automatically load Google Fonts on pages only as they’re used?