bbp_clean_post_cache( object|int $_post = '' )

Will clean a post in the cache.

Description

Will call to clean the term object cache associated with the post ID.

Parameters

$_post

(object|int) (Optional) The post object or ID to remove from the cache

Default value: ''

Source

File: bp-forums/core/cache.php

function bbp_clean_post_cache( $_post = '' ) {

	// Bail if no post
	$_post = get_post( $_post );
	if ( empty( $_post ) )
		return;

	wp_cache_delete( $_post->ID, 'posts'     );
	wp_cache_delete( $_post->ID, 'post_meta' );

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

	do_action( 'bbp_clean_post_cache', $_post->ID, $_post );

	// Child query types to clean
	$post_types = array(
		bbp_get_topic_post_type(),
		bbp_get_forum_post_type(),
		bbp_get_reply_post_type()
	);

	// Loop through query types and clean caches
	foreach ( $post_types as $post_type ) {
		wp_cache_delete( 'bbp_get_forum_'     . $_post->ID . '_reply_id',                              'bbpress_posts' );
		wp_cache_delete( 'bbp_parent_'        . $_post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress_posts' );
		wp_cache_delete( 'bbp_parent_'        . $_post->ID . '_type_' . $post_type . '_child_count',   'bbpress_posts' );
		wp_cache_delete( 'bbp_parent_public_' . $_post->ID . '_type_' . $post_type . '_child_ids',     'bbpress_posts' );
		wp_cache_delete( 'bbp_parent_all_'    . $_post->ID . '_type_' . $post_type . '_child_ids',     'bbpress_posts' );
	}

	// Invalidate parent caches
	if ( ! empty( $_post->post_parent ) ) {
		bbp_clean_post_cache( $_post->post_parent );
	}
}

Changelog

Changelog
Version Description
bbPress (r4040) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.