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

In this article

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

Parameters

$new_statusstringrequired
The status the post is changing to.
$old_statusstringrequired
The status the post is changing from.
$postWP_Postoptional
Post object

Default:null

Source

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

Changelog

VersionDescription
4.9.0Added the $post parameter.
4.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.