bbp_update_post_family_caches( array $objects = array() )

Prime familial post caches.


Description Description

This function uses _prime_post_caches() to prepare the object cache for imminent requests to post objects that aren’t naturally cached by the primary WP_Query calls themselves. Post author caches are also primed.

This is triggered when a update_post_family_cache argument is set to true.

Also see: bbp_update_post_author_caches()


Parameters Parameters

$objects

(Optional) Array of objects, fresh from a query

Default value: array()


Top ↑

Return Return

(bool) True if some IDs were cached


Top ↑

Source Source

File: includes/common/functions.php

function bbp_update_post_family_caches( $objects = array() ) {

	// Bail if no posts
	if ( empty( $objects ) ) {
		return false;
	}

	// Default value
	$post_ids = array();

	// Filter the types of IDs to prime
	$ids = apply_filters( 'bbp_update_post_family_caches', array(
		'_bbp_last_active_id',
		'_bbp_last_reply_id',
		'_bbp_last_topic_id',
		'_bbp_reply_to'
	), $objects );

	// Get the last active IDs
	foreach ( $objects as $object ) {
		$object = get_post( $object );

		// Skip if post ID is empty.
		if ( empty( $object->ID ) ) {
			continue;
		}

		// Meta IDs
		foreach ( $ids as $key ) {
			$post_ids[] = get_post_meta( $object->ID, $key, true );
		}

		// This post ID is already cached, but the post author may not be
		$post_ids[] = $object->ID;
	}

	// Unique, non-zero values
	$post_ids = bbp_get_unique_array_values( $post_ids );

	// Bail if no IDs to prime
	if ( empty( $post_ids ) ) {
		return false;
	}

	// Prime post caches
	_prime_post_caches( $post_ids, true, true );

	// Prime post author caches
	bbp_update_post_author_caches( $post_ids );

	// Return
	return true;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.