Title: clear_embed_cache not working for Multisite/Network
Last modified: February 2, 2021

---

# clear_embed_cache not working for Multisite/Network

 *  Resolved [Fiech](https://wordpress.org/support/users/fiech/)
 * (@fiech)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/clear_embed_cache-not-working-for-multisite-network/)
 * Hi,
 * while trying to solve another problem (I’ll make a separate post), I stumbled
   upon this bug in the clear_embed_cache function (inc/class-embed-privacy.php):
 * It seems that the code does not clear the postmeta tables from old embed-privacy
   entries on multisite installations. The code is here:
 *     ```
       /**
       	 * Embeds are cached in the postmeta database table and need to be removed
       	 * whenever the plugin will be enabled or disabled.
       	 */
       	public function clear_embed_cache() {
       		global $wpdb;
   
       		// the query to delete cache
       		$query = "DELETE FROM	$wpdb->postmeta
       				WHERE			meta_key LIKE '%_oembed_%'";
   
       		if ( is_plugin_active_for_network( 'embed-privacy/embed-privacy.php' ) ) {
       			// on networks we need to iterate through every site
       			$sites = get_sites( 99999 );
   
       			foreach ( $sites as $site ) {
       				switch_to_blog( $site );
       				$wpdb->query( $query );
       			}
       		}
       		else {
       			$wpdb->query( $query );
       		}
       	}
       ```
   
 * The thing is, that the query is not updated to match the blogs’ individual postmeta
   table names. I tried my best coming up with a dynamic solution, but unfortunately
   I could not figure out a way to dynamically the table name, so instead I came
   up with this adapted query to be executed while in the foreach loop:
 *     ```
       $query2 = "DELETE FROM	".$wpdb->get_blog_prefix($site->blog_id)."postmeta
       				WHERE			meta_key LIKE '%_oembed_%'";
       ```
   
 * This query did successfully delete all the post meta data from all the blogs 
   on dis-/reenabling the plugin on my multisite.
 * I think you also can skip the `switch_to_blog` part. Another way would be to 
   use the [delete_post_meta](https://developer.wordpress.org/reference/functions/delete_post_meta/)
   function but then you either have to loop over all post metas to find the keys
   you want to delete or store this information elsewhere.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Matthias Kittsteiner](https://wordpress.org/support/users/kittmedia/)
 * (@kittmedia)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/clear_embed_cache-not-working-for-multisite-network/#post-14009114)
 * Hi there!
 * Thank you for digging into the problem and providing a solution. We will ship
   this fix in the next release.
 * Just as a quick note regarding to delete_post_meta: We used a custom query for
   performance reason to not be forced to iterate over each post, which would be
   dramatically slower.

Viewing 1 replies (of 1 total)

The topic ‘clear_embed_cache not working for Multisite/Network’ is closed to new
replies.

 * ![](https://ps.w.org/embed-privacy/assets/icon.svg?rev=2812349)
 * [Embed Privacy](https://wordpress.org/plugins/embed-privacy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/embed-privacy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/embed-privacy/)
 * [Active Topics](https://wordpress.org/support/plugin/embed-privacy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/embed-privacy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/embed-privacy/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Matthias Kittsteiner](https://wordpress.org/support/users/kittmedia/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/clear_embed_cache-not-working-for-multisite-network/#post-14009114)
 * Status: resolved