wp_defer_comment_counting() WordPress Function

The wp_defer_comment_counting() function is used to defer the counting of comments for a post. This can be useful if you are making changes to a post and don't want the comment count to be updated until you are finished.

wp_defer_comment_counting( bool $defer = null ) #

Determines whether to defer comment counting.


Description

When setting $defer to true, all post comment counts will not be updated until $defer is set to false. When $defer is set to false, then all previously deferred updated post comment counts will then be automatically updated without having to call wp_update_comment_count() after.


Top ↑

Parameters

$defer

(bool)(Optional)

Default value: null


Top ↑

Return

(bool)


Top ↑

Source

File: wp-includes/comment.php

function wp_defer_comment_counting( $defer = null ) {
	static $_defer = false;

	if ( is_bool( $defer ) ) {
		$_defer = $defer;
		// Flush any deferred counts.
		if ( ! $defer ) {
			wp_update_comment_count( null, true );
		}
	}

	return $_defer;
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More