get_object_term_cache

Advertisement

Summery Summery

Retrieves the cached term objects for the given object ID.

Syntax Syntax

get_object_term_cache( int $id, string $taxonomy )

Description Description

Upstream functions (like get_the_terms() and is_object_in_term()) are responsible for populating the object-term relationship cache. The current function only fetches relationship data that is already in the cache.

Parameters Parameters

$id

(Required) Term object ID, for example a post, comment, or user ID.

$taxonomy

(Required) Taxonomy name.

Return Return

(bool|WP_Term[]|WP_Error) Array of WP_Term objects, if cached. False if cache is empty for $taxonomy and $id. WP_Error if get_term() returns an error object for any term.

Source Source

File: wp-includes/taxonomy.php

/**
 * Will remove all of the term IDs from the cache.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb                           WordPress database abstraction object.
 * @global bool $_wp_suspend_cache_invalidation
 *
 * @param int|int[] $ids            Single or array of term IDs.
 * @param string    $taxonomy       Optional. Taxonomy slug. Can be empty, in which case the taxonomies of the passed
 *                                  term IDs will be used. Default empty.
 * @param bool      $clean_taxonomy Optional. Whether to clean taxonomy wide caches (true), or just individual
 *                                  term object caches (false). Default true.
 */
function clean_term_cache( $ids, $taxonomy = '', $clean_taxonomy = true ) {
	global $wpdb, $_wp_suspend_cache_invalidation;

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

	if ( ! is_array( $ids ) ) {
		$ids = array( $ids );
	}

	$taxonomies = array();
	// If no taxonomy, assume tt_ids.
	if ( empty( $taxonomy ) ) {
		$tt_ids = array_map( 'intval', $ids );
		$tt_ids = implode( ', ', $tt_ids );
		$terms  = $wpdb->get_results( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)" );
		$ids    = array();

Advertisement

Changelog Changelog

Changelog
Version Description
4.7.0 Returns a WP_Error object if there's an error with any of the matched terms.
2.3.0 Introduced.

Advertisement

Leave a Reply