_update_generic_term_count

函数
_update_generic_term_count ( $terms, $taxonomy )
参数
  • (int[]) $terms List of term taxonomy IDs.
    Required:
  • (WP_Taxonomy) $taxonomy Current taxonomy object of terms.
    Required:
定义位置
相关方法
_update_post_term_countwp_update_term_countwp_update_network_site_countswp_update_term_count_nowwp_update_network_counts
引入
3.3.0
弃用
-

_update_generic_term_count: 这个函数更新所有分类法的术语计数。它用于确保当一个文章被添加、删除或修改时,所有分类法的术语计数是准确的。

根据对象的数量更新术语计数。

用于’link_category’分类法的默认回调。

function _update_generic_term_count( $terms, $taxonomy ) {
	global $wpdb;

	foreach ( (array) $terms as $term ) {
		$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) );

		/** This action is documented in wp-includes/taxonomy.php */
		do_action( 'edit_term_taxonomy', $term, $taxonomy->name );
		$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );

		/** This action is documented in wp-includes/taxonomy.php */
		do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
	}
}

常见问题

FAQs
查看更多 >