wp_update_term_count

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

WordPress Version: 5.5

/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @since 2.3.0
 *
 * @param int|array $terms       The term_taxonomy_id of the terms.
 * @param string    $taxonomy    The context of the term.
 * @param bool      $do_deferred Whether to flush the deferred term counts too. Default false.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}

WordPress Version: 4.5

/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @since 2.3.0
 *
 * @staticvar array $_deferred
 *
 * @param int|array $terms       The term_taxonomy_id of the terms.
 * @param string    $taxonomy    The context of the term.
 * @param bool      $do_deferred Whether to flush the deferred term counts too. Default false.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}

WordPress Version: 4.3

/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @since 2.3.0
 *
 * @staticvar array $_deferred
 *
 * @param int|array $terms    The term_taxonomy_id of the terms.
 * @param string    $taxonomy The context of the term.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}

WordPress Version: 4.1

/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|array $terms The term_taxonomy_id of the terms
 * @param string $taxonomy The context of the term.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}

WordPress Version: 3.9

/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @since 2.3.0
 * @uses $wpdb
 *
 * @param int|array $terms The term_taxonomy_id of the terms
 * @param string $taxonomy The context of the term.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}

WordPress Version: 3.7

/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 * @uses $wpdb
 *
 * @param int|array $terms The term_taxonomy_id of the terms
 * @param string $taxonomy The context of the term.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}