wp_update_comment_count

The timeline below displays how wordpress function wp_update_comment_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 comment count for post(s).
 *
 * When $do_deferred is false (is by default) and the comments have been set to
 * be deferred, the post_id will be added to a queue, which will be updated at a
 * later date and only updated once per post ID.
 *
 * If the comments have not be set up to be deferred, then the post will be
 * updated. When $do_deferred is set to true, then all previous deferred post
 * IDs will be updated along with the current $post_id.
 *
 * @since 2.1.0
 *
 * @see wp_update_comment_count_now() For what could cause a false return value
 *
 * @param int|null $post_id     Post ID.
 * @param bool     $do_deferred Optional. Whether to process previously deferred
 *                              post comment counts. Default false.
 * @return bool|void True on success, false on failure or if post with ID does
 *                   not exist.
 */
function wp_update_comment_count($post_id, $do_deferred = false)
{
    static $_deferred = array();
    if (empty($post_id) && !$do_deferred) {
        return false;
    }
    if ($do_deferred) {
        $_deferred = array_unique($_deferred);
        foreach ($_deferred as $i => $_post_id) {
            wp_update_comment_count_now($_post_id);
            unset($_deferred[$i]);
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }
    if (wp_defer_comment_counting()) {
        $_deferred[] = $post_id;
        return true;
    } elseif ($post_id) {
        return wp_update_comment_count_now($post_id);
    }
}

WordPress Version: 4.5

/**
 * Updates the comment count for post(s).
 *
 * When $do_deferred is false (is by default) and the comments have been set to
 * be deferred, the post_id will be added to a queue, which will be updated at a
 * later date and only updated once per post ID.
 *
 * If the comments have not be set up to be deferred, then the post will be
 * updated. When $do_deferred is set to true, then all previous deferred post
 * IDs will be updated along with the current $post_id.
 *
 * @since 2.1.0
 * @see wp_update_comment_count_now() For what could cause a false return value
 *
 * @staticvar array $_deferred
 *
 * @param int|null $post_id     Post ID.
 * @param bool     $do_deferred Optional. Whether to process previously deferred
 *                              post comment counts. Default false.
 * @return bool|void True on success, false on failure or if post with ID does
 *                   not exist.
 */
function wp_update_comment_count($post_id, $do_deferred = false)
{
    static $_deferred = array();
    if (empty($post_id) && !$do_deferred) {
        return false;
    }
    if ($do_deferred) {
        $_deferred = array_unique($_deferred);
        foreach ($_deferred as $i => $_post_id) {
            wp_update_comment_count_now($_post_id);
            unset($_deferred[$i]);
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }
    if (wp_defer_comment_counting()) {
        $_deferred[] = $post_id;
        return true;
    } elseif ($post_id) {
        return wp_update_comment_count_now($post_id);
    }
}

WordPress Version: 4.3

/**
 * Updates the comment count for post(s).
 *
 * When $do_deferred is false (is by default) and the comments have been set to
 * be deferred, the post_id will be added to a queue, which will be updated at a
 * later date and only updated once per post ID.
 *
 * If the comments have not be set up to be deferred, then the post will be
 * updated. When $do_deferred is set to true, then all previous deferred post
 * IDs will be updated along with the current $post_id.
 *
 * @since 2.1.0
 * @see wp_update_comment_count_now() For what could cause a false return value
 *
 * @staticvar array $_deferred
 *
 * @param int $post_id Post ID
 * @param bool $do_deferred Whether to process previously deferred post comment counts
 * @return bool|void True on success, false on failure
 */
function wp_update_comment_count($post_id, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        $_deferred = array_unique($_deferred);
        foreach ($_deferred as $i => $_post_id) {
            wp_update_comment_count_now($_post_id);
            unset($_deferred[$i]);
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }
    if (wp_defer_comment_counting()) {
        $_deferred[] = $post_id;
        return true;
    } elseif ($post_id) {
        return wp_update_comment_count_now($post_id);
    }
}

WordPress Version: 4.1

/**
 * Updates the comment count for post(s).
 *
 * When $do_deferred is false (is by default) and the comments have been set to
 * be deferred, the post_id will be added to a queue, which will be updated at a
 * later date and only updated once per post ID.
 *
 * If the comments have not be set up to be deferred, then the post will be
 * updated. When $do_deferred is set to true, then all previous deferred post
 * IDs will be updated along with the current $post_id.
 *
 * @since 2.1.0
 * @see wp_update_comment_count_now() For what could cause a false return value
 *
 * @param int $post_id Post ID
 * @param bool $do_deferred Whether to process previously deferred post comment counts
 * @return bool|null True on success, false on failure
 */
function wp_update_comment_count($post_id, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        $_deferred = array_unique($_deferred);
        foreach ($_deferred as $i => $_post_id) {
            wp_update_comment_count_now($_post_id);
            unset($_deferred[$i]);
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }
    if (wp_defer_comment_counting()) {
        $_deferred[] = $post_id;
        return true;
    } elseif ($post_id) {
        return wp_update_comment_count_now($post_id);
    }
}

WordPress Version: 3.7

/**
 * Updates the comment count for post(s).
 *
 * When $do_deferred is false (is by default) and the comments have been set to
 * be deferred, the post_id will be added to a queue, which will be updated at a
 * later date and only updated once per post ID.
 *
 * If the comments have not be set up to be deferred, then the post will be
 * updated. When $do_deferred is set to true, then all previous deferred post
 * IDs will be updated along with the current $post_id.
 *
 * @since 2.1.0
 * @see wp_update_comment_count_now() For what could cause a false return value
 *
 * @param int $post_id Post ID
 * @param bool $do_deferred Whether to process previously deferred post comment counts
 * @return bool True on success, false on failure
 */
function wp_update_comment_count($post_id, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        $_deferred = array_unique($_deferred);
        foreach ($_deferred as $i => $_post_id) {
            wp_update_comment_count_now($_post_id);
            unset($_deferred[$i]);
            /** @todo Move this outside of the foreach and reset $_deferred to an array instead */
        }
    }
    if (wp_defer_comment_counting()) {
        $_deferred[] = $post_id;
        return true;
    } elseif ($post_id) {
        return wp_update_comment_count_now($post_id);
    }
}