_update_posts_count_on_transition_post_status() WordPress Function

The _update_posts_count_on_transition_post_status() function is a utility function that is used to update the count of posts for a given post type when the post status is changed. This function is typically used when a post is published or unpublished.

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

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


Parameters

$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)(Optional)Post object

Default value: null


Top ↑

Source

File: wp-includes/ms-blogs.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();
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Added the $post parameter.
4.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.