update_posts_count

函式
update_posts_count ( $deprecated = '' )
引數
  • (string) $deprecated Not used.
    Required:
    Default: (empty)
定義位置
相關方法
_update_post_term_count_update_posts_count_on_deleteupdate_post_metaupdate_post_cachewp_update_term_count
引入
-
棄用
-

update_posts_count: 這個函式更新一個給定分類法的文章數量。它需要兩個引數:$terms和$taxonomy。$terms是一個需要更新文章計數的術語ID的陣列。$taxonomy是需要更新文章數量的分類法的名稱。

更新一個部落格的文章數。

WordPress MS將一個部落格的文章數作為一個選項來儲存,以避免在用get_site()函式獲取一個部落格的詳細資訊時出現多餘的COUNT: 當文章釋出或未釋出時,這個函式被呼叫,以確保計數保持最新。”

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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'" ) );
}
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'" ) ); }
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'" ) );
}

常見問題

FAQs
檢視更多 >