_update_generic_term_count()WP 3.3.0

Updates term count based on number of objects.

Default callback for the link_category

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

Returns

null. Nothing (null).

Usage

_update_generic_term_count( $terms, $taxonomy );
$terms(int[]) (required)
List of term taxonomy IDs.
$taxonomy(WP_Taxonomy) (required)
Current taxonomy object of terms.

Notes

  • Global. wpdb. $wpdb WordPress database abstraction object.

Changelog

Since 3.3.0 Introduced.

_update_generic_term_count() code WP 6.9.1

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( 'update_term_count', $term, $taxonomy->name, $count );

		/** 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 );
	}
}