wp_update_comment_count

Advertisement

Summery Summery

Updates the comment count for post(s).

Syntax Syntax

wp_update_comment_count( int|null $post_id, bool $do_deferred = false )

Description Description

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.

Parameters Parameters

$post_id

(Required) Post ID.

$do_deferred

(Optional) Whether to process previously deferred post comment counts.

Default value: false

Return Return

(bool|void) True on success, false on failure or if post with ID does not exist.

Source Source

File: wp-includes/comment.php

	// Merge old and new fields with new fields overwriting old ones.
	$commentarr = array_merge( $comment, $commentarr );

	$commentarr = wp_filter_comment( $commentarr );

	// Now extract the merged array.
	$data = wp_unslash( $commentarr );

	/**
	 * Filters the comment content before it is updated in the database.
	 *
	 * @since 1.5.0
	 *
	 * @param string $comment_content The comment data.
	 */
	$data['comment_content'] = apply_filters( 'comment_save_pre', $data['comment_content'] );

	$data['comment_date_gmt'] = get_gmt_from_date( $data['comment_date'] );

	if ( ! isset( $data['comment_approved'] ) ) {
		$data['comment_approved'] = 1;
	} elseif ( 'hold' === $data['comment_approved'] ) {
		$data['comment_approved'] = 0;
	} elseif ( 'approve' === $data['comment_approved'] ) {

Advertisement

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

See also See also

Advertisement

Leave a Reply