Title: clean_post_cache
Published: April 25, 2014
Last modified: August 20, 2026

---

# clean_post_cache( int|WP_Post $post )

## In this article

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

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

Will clean the post in the cache.

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

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()](https://developer.wordpress.org/reference/functions/wp_suspend_cache_invalidation/).

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/clean_post_cache/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
required

Post ID or post object to remove from the cache.

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

    ```php
    function clean_post_cache( $post ) {
    	global $_wp_suspend_cache_invalidation;

    	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    		return;
    	}

    	$post = get_post( $post );

    	if ( ! $post ) {
    		return;
    	}

    	wp_cache_delete( $post->ID, 'posts' );
    	wp_cache_delete( 'post_parent:' . (string) $post->ID, 'posts' );
    	wp_cache_delete( $post->ID, 'post_meta' );

    	clean_object_term_cache( $post->ID, $post->post_type );

    	wp_cache_delete( 'wp_get_archives', 'general' );

    	/**
    	 * Fires immediately after the given post's cache is cleaned.
    	 *
    	 * @since 2.5.0
    	 *
    	 * @param int     $post_id Post ID.
    	 * @param WP_Post $post    Post object.
    	 */
    	do_action( 'clean_post_cache', $post->ID, $post );

    	if ( 'page' === $post->post_type ) {
    		wp_cache_delete( 'all_page_ids', 'posts' );

    		/**
    		 * Fires immediately after the given page's cache is cleaned.
    		 *
    		 * @since 2.5.0
    		 *
    		 * @param int $post_id Post ID.
    		 */
    		do_action( 'clean_page_cache', $post->ID );
    	}

    	wp_cache_set_posts_last_changed();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/post.php#L7940)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/post.php#L7940-L7985)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/clean_post_cache/?output_format=md#hooks)󠁿

 [do_action( ‘clean_page_cache’, int $post_id )](https://developer.wordpress.org/reference/hooks/clean_page_cache/)

Fires immediately after the given page’s cache is cleaned.

 [do_action( ‘clean_post_cache’, int $post_id, WP_Post $post )](https://developer.wordpress.org/reference/hooks/clean_post_cache/)

Fires immediately after the given post’s cache is cleaned.

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

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

Sets the last changed time for the ‘posts’ cache group.

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

Removes the cache contents matching key and group.

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

Removes the taxonomy relationship to terms from the cache.

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

Calls the callback functions that have been added to an action hook.

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

Retrieves post data given a post ID or post object.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/clean_post_cache/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/clean_post_cache/?output_format=md#)

| Used by | Description | 
| [WP_Customize_Manager::trash_changeset_post()](https://developer.wordpress.org/reference/classes/wp_customize_manager/trash_changeset_post/)`wp-includes/class-wp-customize-manager.php` |

Trashes or deletes a changeset post.

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

Makes sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection.

  | 
| [WP_Customize_Manager::_publish_changeset_values()](https://developer.wordpress.org/reference/classes/wp_customize_manager/_publish_changeset_values/)`wp-includes/class-wp-customize-manager.php` |

Publishes the values of a changeset.

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

Adds a trashed suffix for a given post.

  | 
| [wp_delete_user()](https://developer.wordpress.org/reference/functions/wp_delete_user/)`wp-admin/includes/user.php` |

Delete user and optionally reassign posts and links to another user.

  | 
| [WP_Posts_List_Table::_display_rows_hierarchical()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/_display_rows_hierarchical/)`wp-admin/includes/class-wp-posts-list-table.php` |  | 
| [clean_page_cache()](https://developer.wordpress.org/reference/functions/clean_page_cache/)`wp-includes/deprecated.php` |

Will clean the page in the cache.

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

Trashes or deletes an attachment.

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

Publishes a post by transitioning the post status.

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

Adds a URL to those already pinged.

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

Inserts or updates a post in the database.

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

Trashes or deletes a post or page.

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

Updates the post type for the post ID.

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

Updates the comment count for the post.

  |

[Show 9 more](https://developer.wordpress.org/reference/functions/clean_post_cache/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/clean_post_cache/?output_format=md#)

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

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

## User Contributed Notes

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