wp_update_term_count_now

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

WordPress Version: 6.3

/**
 * Performs term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array  $terms    The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return true Always true when complete.
 */
function wp_update_term_count_now($terms, $taxonomy)
{
    $terms = array_map('intval', $terms);
    $taxonomy = get_taxonomy($taxonomy);
    if (!empty($taxonomy->update_count_callback)) {
        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    } else {
        $object_types = (array) $taxonomy->object_type;
        foreach ($object_types as &$object_type) {
            if (str_starts_with($object_type, 'attachment:')) {
                list($object_type) = explode(':', $object_type);
            }
        }
        if (array_filter($object_types, 'post_type_exists') == $object_types) {
            // Only post types are attached to this taxonomy.
            _update_post_term_count($terms, $taxonomy);
        } else {
            // Default count updater.
            _update_generic_term_count($terms, $taxonomy);
        }
    }
    clean_term_cache($terms, '', false);
    return true;
}

WordPress Version: 6.1

/**
 * Performs term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array  $terms    The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return true Always true when complete.
 */
function wp_update_term_count_now($terms, $taxonomy)
{
    $terms = array_map('intval', $terms);
    $taxonomy = get_taxonomy($taxonomy);
    if (!empty($taxonomy->update_count_callback)) {
        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    } else {
        $object_types = (array) $taxonomy->object_type;
        foreach ($object_types as &$object_type) {
            if (0 === strpos($object_type, 'attachment:')) {
                list($object_type) = explode(':', $object_type);
            }
        }
        if (array_filter($object_types, 'post_type_exists') == $object_types) {
            // Only post types are attached to this taxonomy.
            _update_post_term_count($terms, $taxonomy);
        } else {
            // Default count updater.
            _update_generic_term_count($terms, $taxonomy);
        }
    }
    clean_term_cache($terms, '', false);
    return true;
}

WordPress Version: 5.4

/**
 * Perform term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array  $terms    The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return true Always true when complete.
 */
function wp_update_term_count_now($terms, $taxonomy)
{
    $terms = array_map('intval', $terms);
    $taxonomy = get_taxonomy($taxonomy);
    if (!empty($taxonomy->update_count_callback)) {
        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    } else {
        $object_types = (array) $taxonomy->object_type;
        foreach ($object_types as &$object_type) {
            if (0 === strpos($object_type, 'attachment:')) {
                list($object_type) = explode(':', $object_type);
            }
        }
        if (array_filter($object_types, 'post_type_exists') == $object_types) {
            // Only post types are attached to this taxonomy.
            _update_post_term_count($terms, $taxonomy);
        } else {
            // Default count updater.
            _update_generic_term_count($terms, $taxonomy);
        }
    }
    clean_term_cache($terms, '', false);
    return true;
}

WordPress Version: 4.3

/**
 * Perform term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array  $terms    The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return true Always true when complete.
 */
function wp_update_term_count_now($terms, $taxonomy)
{
    $terms = array_map('intval', $terms);
    $taxonomy = get_taxonomy($taxonomy);
    if (!empty($taxonomy->update_count_callback)) {
        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    } else {
        $object_types = (array) $taxonomy->object_type;
        foreach ($object_types as &$object_type) {
            if (0 === strpos($object_type, 'attachment:')) {
                list($object_type) = explode(':', $object_type);
            }
        }
        if ($object_types == array_filter($object_types, 'post_type_exists')) {
            // Only post types are attached to this taxonomy
            _update_post_term_count($terms, $taxonomy);
        } else {
            // Default count updater
            _update_generic_term_count($terms, $taxonomy);
        }
    }
    clean_term_cache($terms, '', false);
    return true;
}

WordPress Version: 4.0

/**
 * Perform term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array $terms The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return bool Always true when complete.
 */
function wp_update_term_count_now($terms, $taxonomy)
{
    $terms = array_map('intval', $terms);
    $taxonomy = get_taxonomy($taxonomy);
    if (!empty($taxonomy->update_count_callback)) {
        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    } else {
        $object_types = (array) $taxonomy->object_type;
        foreach ($object_types as &$object_type) {
            if (0 === strpos($object_type, 'attachment:')) {
                list($object_type) = explode(':', $object_type);
            }
        }
        if ($object_types == array_filter($object_types, 'post_type_exists')) {
            // Only post types are attached to this taxonomy
            _update_post_term_count($terms, $taxonomy);
        } else {
            // Default count updater
            _update_generic_term_count($terms, $taxonomy);
        }
    }
    clean_term_cache($terms, '', false);
    return true;
}

WordPress Version: 3.7

/**
 * Perform term count update immediately.
 *
 * @since 2.5.0
 *
 * @param array $terms The term_taxonomy_id of terms to update.
 * @param string $taxonomy The context of the term.
 * @return bool Always true when complete.
 */
function wp_update_term_count_now($terms, $taxonomy)
{
    global $wpdb;
    $terms = array_map('intval', $terms);
    $taxonomy = get_taxonomy($taxonomy);
    if (!empty($taxonomy->update_count_callback)) {
        call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
    } else {
        $object_types = (array) $taxonomy->object_type;
        foreach ($object_types as &$object_type) {
            if (0 === strpos($object_type, 'attachment:')) {
                list($object_type) = explode(':', $object_type);
            }
        }
        if ($object_types == array_filter($object_types, 'post_type_exists')) {
            // Only post types are attached to this taxonomy
            _update_post_term_count($terms, $taxonomy);
        } else {
            // Default count updater
            _update_generic_term_count($terms, $taxonomy);
        }
    }
    clean_term_cache($terms, '', false);
    return true;
}