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

---

# _update_posts_count_on_transition_post_status( string $new_status, string $old_status, WP_Post $post = null )

## In this article

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

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

Handler for updating the current site’s posts count when a post status changes.

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

 `$new_status`stringrequired

The status the post is changing to.

`$old_status`stringrequired

The status the post is changing from.

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

Post object

Default:`null`

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

    ```php
    function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) {
    	if ( $new_status === $old_status ) {
    		return;
    	}

    	if ( 'post' !== get_post_type( $post ) ) {
    		return;
    	}

    	if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
    		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#L911)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/ms-blogs.php#L911-L925)

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

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

Retrieves the post type of the current post or of a given post.

  | 
| [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_transition_post_status/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.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_transition_post_status%2F)
before being able to contribute a note or feedback.