Title: [Plugin: WP Widget Cache] Widget Cache Remove Function
Last modified: August 19, 2016

---

# [Plugin: WP Widget Cache] Widget Cache Remove Function

 *  [Rishi](https://wordpress.org/support/users/rishk789/)
 * (@rishk789)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-widget-cache-widget-cache-remove-function/)
 * Hello all,
 * I am trying to use WP-Widget-Cache to cache a specific part of my sidebar while
   keeping everything else dynamic. I surrounded the code I want cached with the
   following:
 *     ```
       <?php while($widget_cache->wcache->save($widget_cache->get_widget_cache_key("12344321"),9999, array())) { ?>
   
       THE CODE I WANT CACHED
   
       <?php } ?>
       ```
   
 * This caches the code just fine. =) Now, I want the cache to be cleared each time
   certain actions occur (comment is posted, post is published, etc.)
 * This is what I added to my functions.php file. The custom_clearwcache function
   should clear the cached code based on the ID:
 * `function custom_clearwcache(){widget_cache_remove("12344321");}`
 * The following loop executes the custom_clearwcache function for all the actions
   I require (adding a link, deleting a link, etc.)
 *     ```
       $custom_action_arr=array("add_link", "delete_link", "edit_link", "add_category", "delete_category", "publish_page","publish_post","comment_post","comment_post","deleted_post", "edit_comment","delete_comment","wp_set_comment_status");
       foreach($custom_action_arr as $ca)
       {
       add_action('ca', 'custom_clearwcache');
       }
       ```
   
 * I tried adding a dummy comment and adding a test link to my blogroll, but neither
   of those actions would clear the cache. Is there some syntax error I’ve committed
   or something I’ve overlooked entirely regarding the add_action function?
 * [http://wordpress.org/extend/plugins/wp-widget-cache/](http://wordpress.org/extend/plugins/wp-widget-cache/)

The topic ‘[Plugin: WP Widget Cache] Widget Cache Remove Function’ is closed to 
new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-widget-cache.svg)
 * [WP Widget Cache](https://wordpress.org/plugins/wp-widget-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-widget-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-widget-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-widget-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-widget-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-widget-cache/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Rishi](https://wordpress.org/support/users/rishk789/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-widget-cache-widget-cache-remove-function/)
 * Status: not resolved