update_posts_count()更新站点文章总数(多站点)

目录

描述

Update a blog's post count.

update_posts_count() 描述

用法

<?php update_posts_count$deprecated ); ?>

update_posts_count() 用法

参数

$deprecated

(string) (可选) do not pass a parameter to this function

默认值: empty string

update_posts_count() 参数

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

update_posts_count() 示例

注意

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_blog_details(). This function is called when posts are published to make sure the count stays current.

update_posts_count() 注意

历史

添加于 版本: MU

update_posts_count() 历史

源文件

update_posts_count() 函数的代码位于 wp-includes/ms-functions.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Update a blog's post count.
 *
 * 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_blog_details(). This function is called when posts
 * are published or unpublished to make sure the count stays current.
 *
 * @since MU
 *
 * @global wpdb $wpdb
 */
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'" ) );
}

update_posts_count() 源文件

相关