Title: wp_defer_comment_counting
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_defer_comment_counting( bool $defer = null ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#wp--skip-link--target)

Determines whether to defer comment counting.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#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()](https://developer.wordpress.org/reference/functions/wp_update_comment_count/)
after.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#parameters)󠁿

 `$defer`booloptional

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#return)󠁿

 bool

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#source)󠁿

    ```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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/comment.php#L2774)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/comment.php#L2774-L2786)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_update_comment_count()](https://developer.wordpress.org/reference/functions/wp_update_comment_count/)`wp-includes/comment.php` |

Updates the comment count for post(s).

  |

| Used by | Description | 
| [wp_delete_attachment()](https://developer.wordpress.org/reference/functions/wp_delete_attachment/)`wp-includes/post.php` |

Trashes or deletes an attachment.

  | 
| [wp_delete_post()](https://developer.wordpress.org/reference/functions/wp_delete_post/)`wp-includes/post.php` |

Trashes or deletes a post or page.

  | 
| [wp_update_comment_count()](https://developer.wordpress.org/reference/functions/wp_update_comment_count/)`wp-includes/comment.php` |

Updates the comment count for post(s).

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_defer_comment_counting/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_defer_comment_counting%2F)
before being able to contribute a note or feedback.