Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_prime_term_caches() WordPress Function

The prime_term_caches() function is a caching mechanism for terms in the WordPress taxonomy. This function is called when a term is first created or updated. It ensures that the term's cached data is refreshed and accurate. This function is important for performance, as it reduces the number of database queries needed to retrieve taxonomy data.

_prime_term_caches( array $term_ids, bool $update_meta_cache = true ) #

Adds any terms from the given IDs to the cache that do not already exist in cache.


Parameters

$term_ids

(array)(Required)Array of term IDs.

$update_meta_cache

(bool)(Optional) Whether to update the meta cache.

Default value: true


Top ↑

Source

File: wp-includes/taxonomy.php

function _prime_term_caches( $term_ids, $update_meta_cache = true ) {
	global $wpdb;

	$non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' );
	if ( ! empty( $non_cached_ids ) ) {
		$fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) );

		update_term_cache( $fresh_terms );

		if ( $update_meta_cache ) {
			update_termmeta_cache( $non_cached_ids );
		}
	}
}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More