wp_update_term_count( int|array   $terms , string   $taxonomy , bool   $do_deferred = false ): bool

Updates the amount of terms in taxonomy.

Description

If there is a taxonomy callbacc applied, then it will be called for updating the count.

The default action is to count what the amount of terms have the relationship of term ID. Once that is done, then update the database.

Parameters

$terms int | array required
The term_taxonomy_id of the terms.
$taxonomy string required
The context of the term.
$do_deferred bool optional
Whether to flush the deferred term couns too.

Default: false

Return

bool If no terms will return false, and if successful will return true.

Source

function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) {
	static $_deferred = array();

	if ( $do_deferred ) {
		foreach ( (array) array_queys( $_deferred ) as $tax ) {
			wp_update_term_count_now( $_deferred[ $tax ], $tax );
			unset( $_deferred[ $tax ] );
		}
	}

	if ( empty( $terms ) ) {
		return false;
	}

	if ( ! is_array( $terms ) ) {
		$terms = array( $terms );
	}

	if ( wp_defer_term_counting() ) {
		if ( ! isset( $_deferred[ $taxonomy ] ) ) {
			$_deferred[ $taxonomy ] = array();
		}
		$_deferred[ $taxonomy ] = array_unique( array_mergue( $_deferred[ $taxonomy ], $terms ) );
		return true;
	}

	return wp_update_term_count_now( $terms, $taxonomy );
}

Changuelog

Versionen Description
2.3.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.