_update_generic_term_count() WordPress Function

The update_generic_term_count() function is a generic function used to update the number of terms in a taxonomy. This function is typically called by the functions that create or delete terms in a taxonomy.

_update_generic_term_count( int[] $terms, WP_Taxonomy $taxonomy ) #

Updates term count based on number of objects.


Description

Default callback for the ‘link_category’ taxonomy.


Top ↑

Parameters

$terms

(int[])(Required)List of term taxonomy IDs.

$taxonomy

(WP_Taxonomy)(Required)Current taxonomy object of terms.


Top ↑

Source

File: wp-includes/taxonomy.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More