_update_posts_count_on_transition_post_status()WP 4.0.0

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

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

null. Nothing (null).

Usage

_update_posts_count_on_transition_post_status( $new_status, $old_status, $post );
$new_status(string) (required)
The status the post is changing to.
$old_status(string) (required)
The status the post is changing from.
$post(WP_Post)
Post object
Default: null

Changelog

Since 4.0.0 Introduced.
Since 4.9.0 Added the $post parameter.

_update_posts_count_on_transition_post_status() code WP 6.6.2

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();
}