Title: wp_cache_switch_to_blog_fallback
Published: May 20, 2026

---

# wp_cache_switch_to_blog_fallback()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#wp--skip-link--target)

Fallback logic for switching cache context when an object cache drop-in lacks a 
[switch_to_blog()](https://developer.wordpress.org/reference/functions/switch_to_blog/)
method.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#description)󠁿

Reinitializes the cache and restores global/non-persistent groups.

Used by the [wp_cache_switch_to_blog()](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog/)
compatibility function, abstracted only to allow for unit testing outside of the
drop-in plugin inclusion circus.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#source)󠁿

    ```php
    function wp_cache_switch_to_blog_fallback() {
    	global $wp_object_cache;

    	$global_groups         = false;
    	$non_persistent_groups = false;

    	if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) && is_array( $wp_object_cache->global_groups ) ) {

    		// Get the global groups as they are.
    		$group_names = $wp_object_cache->global_groups;

    		// Get global group keys if non-numeric array.
    		if ( ! wp_is_numeric_array( $group_names ) ) {
    			$group_names = array_keys( $group_names );
    		}

    		$global_groups = $group_names;

    		/*
    		 * Non-persistent groups: Check for no_mc_groups first (memcached drop-in).
    		 * Fall back to cache structure (default cache).
    		 */
    		if ( isset( $wp_object_cache->no_mc_groups ) && is_array( $wp_object_cache->no_mc_groups ) && ! empty( $wp_object_cache->no_mc_groups ) ) {
    			$non_persistent_groups = $wp_object_cache->no_mc_groups;
    		} elseif ( isset( $wp_object_cache->cache ) && is_array( $wp_object_cache->cache ) ) {
    			$all_groups            = array_keys( $wp_object_cache->cache );
    			$non_persistent_groups = array_values( array_diff( $all_groups, $global_groups ) );
    		}
    	}

    	wp_cache_init();

    	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    		if ( ! is_array( $global_groups ) || empty( $global_groups ) ) {
    			$global_groups = array(
    				'blog-details',
    				'blog-id-cache',
    				'blog-lookup',
    				'blog_meta',
    				'global-posts',
    				'image_editor',
    				'networks',
    				'network-queries',
    				'sites',
    				'site-details',
    				'site-options',
    				'site-queries',
    				'site-transient',
    				'theme_files',
    				'translation_files',
    				'rss',
    				'users',
    				'user-queries',
    				'user_meta',
    				'useremail',
    				'userlogins',
    				'userslugs',
    			);
    		}

    		wp_cache_add_global_groups( $global_groups );
    	}

    	if ( function_exists( 'wp_cache_add_non_persistent_groups' ) ) {
    		if ( ! is_array( $non_persistent_groups ) || empty( $non_persistent_groups ) ) {
    			$non_persistent_groups = array(
    				'counts',
    				'plugins',
    				'theme_json',
    			);
    		}

    		wp_cache_add_non_persistent_groups( $non_persistent_groups );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-blogs.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ms-blogs.php#L611)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ms-blogs.php#L611-L685)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_numeric_array()](https://developer.wordpress.org/reference/functions/wp_is_numeric_array/)`wp-includes/functions.php` |

Determines if the variable is a numeric-indexed array.

  | 
| [wp_cache_init()](https://developer.wordpress.org/reference/functions/wp_cache_init/)`wp-includes/cache.php` |

Sets up Object Cache Global and assigns it.

  | 
| [wp_cache_add_global_groups()](https://developer.wordpress.org/reference/functions/wp_cache_add_global_groups/)`wp-includes/cache.php` |

Adds a group or set of groups to the list of global groups.

  | 
| [wp_cache_add_non_persistent_groups()](https://developer.wordpress.org/reference/functions/wp_cache_add_non_persistent_groups/)`wp-includes/cache.php` |

Adds a group or set of groups to the list of non-persistent groups.

  |

| Used by | Description | 
| [wp_cache_switch_to_blog()](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog/)`wp-includes/cache.php` |

Switches the internal blog ID.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_cache_switch_to_blog_fallback/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_cache_switch_to_blog_fallback%2F)
before being able to contribute a note or feedback.