Title: _update_posts_count_on_delete
Published: September 4, 2014
Last modified: February 24, 2026

---

# _update_posts_count_on_delete( int $post_id, WP_Post $post )

## In this article

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

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

Handler for updating the current site’s posts count when a post is deleted.

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

 `$post_id`intrequired

Post ID.

`$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)required

Post object.

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

    ```php
    function _update_posts_count_on_delete( $post_id, $post ) {
    	if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) {
    		return;
    	}

    	update_posts_count();
    }
    ```

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

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

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

Updates a blog’s post count.

  |

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

| Version | Description | 
| [6.2.0](https://developer.wordpress.org/reference/since/6.2.0/) | Added the `$post` parameter. | 
| [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. |

## User Contributed Notes

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