On this page
update_posts_count( string $deprecated = '' )
Updates a blog’s post count.
Description
WordPress MS stores a blog’s post count as an option so as to avoid extraneous COUNTs when a blog’s details are fetched with get_site() . This function is called when posts are published or unpublished to make sure the count stays current.
Parameters
$deprecatedstring Optional-
Not used.
Default:
''
Source
File: wp-includes/ms-functions.php. View all references
function update_posts_count( $deprecated = '' ) {
global $wpdb;
update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) );
}
Related
Uses
| Uses | Description |
|---|---|
| update_option() wp-includes/option.php | Updates the value of an option that was already added. |
| wpdb::get_var() wp-includes/class-wpdb.php | Retrieves one variable from the database. |
Used By
| Used By | Description |
|---|---|
| _update_posts_count_on_delete() wp-includes/ms-blogs.php | Handler for updating the current site’s posts count when a post is deleted. |
| _update_posts_count_on_transition_post_status() wp-includes/ms-blogs.php | Handler for updating the current site’s posts count when a post status changes. |
| wp_install_defaults() wp-admin/includes/upgrade.php | Creates the initial content for a newly-installed site. |
Changelog
| Version | Description |
|---|---|
| MU (3.0.0) | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/update_posts_count