update_term_cache

The timeline below displays how wordpress function update_term_cache has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Updates terms in cache.
 *
 * @since 2.3.0
 *
 * @param WP_Term[] $terms    Array of term objects to change.
 * @param string    $taxonomy Not used.
 */
function update_term_cache($terms, $taxonomy = '')
{
    $data = array();
    foreach ((array) $terms as $term) {
        // Create a copy in case the array was passed by reference.
        $_term = clone $term;
        // Object ID should not be cached.
        unset($_term->object_id);
        $data[$term->term_id] = $_term;
    }
    wp_cache_add_multiple($data, 'terms');
}

WordPress Version: 5.4

/**
 * Updates Terms to Taxonomy in cache.
 *
 * @since 2.3.0
 *
 * @param WP_Term[] $terms    Array of term objects to change.
 * @param string    $taxonomy Not used.
 */
function update_term_cache($terms, $taxonomy = '')
{
    foreach ((array) $terms as $term) {
        // Create a copy in case the array was passed by reference.
        $_term = clone $term;
        // Object ID should not be cached.
        unset($_term->object_id);
        wp_cache_add($term->term_id, $_term, 'terms');
    }
}

WordPress Version: .10

/**
 * Updates Terms to Taxonomy in cache.
 *
 * @since 2.3.0
 *
 * @param array  $terms    List of term objects to change.
 * @param string $taxonomy Optional. Update Term to this taxonomy in cache. Default empty.
 */
function update_term_cache($terms, $taxonomy = '')
{
    foreach ((array) $terms as $term) {
        // Create a copy in case the array was passed by reference.
        $_term = clone $term;
        // Object ID should not be cached.
        unset($_term->object_id);
        wp_cache_add($term->term_id, $_term, 'terms');
    }
}

WordPress Version: 4.4

/**
 * Updates Terms to Taxonomy in cache.
 *
 * @since 2.3.0
 *
 * @param array  $terms    List of term objects to change.
 * @param string $taxonomy Optional. Update Term to this taxonomy in cache. Default empty.
 */
function update_term_cache($terms, $taxonomy = '')
{
    foreach ((array) $terms as $term) {
        // Create a copy in case the array was passed by reference.
        $_term = $term;
        // Object ID should not be cached.
        unset($_term->object_id);
        wp_cache_add($term->term_id, $_term, 'terms');
    }
}

WordPress Version: 4.3

/**
 * Updates Terms to Taxonomy in cache.
 *
 * @since 2.3.0
 *
 * @param array  $terms    List of term objects to change.
 * @param string $taxonomy Optional. Update Term to this taxonomy in cache. Default empty.
 */
function update_term_cache($terms, $taxonomy = '')
{
    foreach ((array) $terms as $term) {
        $term_taxonomy = $taxonomy;
        if (empty($term_taxonomy)) {
            $term_taxonomy = $term->taxonomy;
        }
        wp_cache_add($term->term_id, $term, $term_taxonomy);
    }
}

WordPress Version: 3.9

/**
 * Updates Terms to Taxonomy in cache.
 *
 * @since 2.3.0
 *
 * @param array $terms List of Term objects to change
 * @param string $taxonomy Optional. Update Term to this taxonomy in cache
 */
function update_term_cache($terms, $taxonomy = '')
{
    foreach ((array) $terms as $term) {
        $term_taxonomy = $taxonomy;
        if (empty($term_taxonomy)) {
            $term_taxonomy = $term->taxonomy;
        }
        wp_cache_add($term->term_id, $term, $term_taxonomy);
    }
}

WordPress Version: 3.7

/**
 * Updates Terms to Taxonomy in cache.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 *
 * @param array $terms List of Term objects to change
 * @param string $taxonomy Optional. Update Term to this taxonomy in cache
 */
function update_term_cache($terms, $taxonomy = '')
{
    foreach ((array) $terms as $term) {
        $term_taxonomy = $taxonomy;
        if (empty($term_taxonomy)) {
            $term_taxonomy = $term->taxonomy;
        }
        wp_cache_add($term->term_id, $term, $term_taxonomy);
    }
}