clean_post_cache

Will clean the post in the cache.

Description

clean_post_cache( (int|WP_Post) $post ); 

Cleaning means delete from the cache of the post. Will call to clean the term object cache associated with the post ID.

This function not run if $_wp_suspend_cache_invalidation is not empty. See wp_suspend_cache_invalidation().

Parameters (1)

0. $post (int|WP_Post)
Post ID or post object to remove from the cache.

Usage

  1. if ( !function_exists( 'clean_post_cache' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Post ID or post object to remove from the cache. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = clean_post_cache($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function clean_post_cache( $post ) { 
  2. global $_wp_suspend_cache_invalidation; 
  3.  
  4. if ( ! empty( $_wp_suspend_cache_invalidation ) ) 
  5. return; 
  6.  
  7. $post = get_post( $post ); 
  8. if ( empty( $post ) ) 
  9. return; 
  10.  
  11. wp_cache_delete( $post->ID, 'posts' ); 
  12. wp_cache_delete( $post->ID, 'post_meta' ); 
  13.  
  14. clean_object_term_cache( $post->ID, $post->post_type ); 
  15.  
  16. wp_cache_delete( 'wp_get_archives', 'general' ); 
  17.  
  18. /** 
  19. * Fires immediately after the given post's cache is cleaned. 
  20. * @since 2.5.0 
  21. * @param int $post_id Post ID. 
  22. * @param WP_Post $post Post object. 
  23. */ 
  24. do_action( 'clean_post_cache', $post->ID, $post ); 
  25.  
  26. if ( 'page' == $post->post_type ) { 
  27. wp_cache_delete( 'all_page_ids', 'posts' ); 
  28.  
  29. /** 
  30. * Fires immediately after the given page's cache is cleaned. 
  31. * @since 2.5.0 
  32. * @param int $post_id Post ID. 
  33. */ 
  34. do_action( 'clean_page_cache', $post->ID ); 
  35.  
  36. wp_cache_set( 'last_changed', microtime(), 'posts' );