立即执行术语计数更新。

原型

wp_update_term_count_now( array $terms, string $taxonomy )

参数

$terms (array) (Required) 要更新的术语term_taxonomy_id。

$taxonomy (string) (Required) 该术语的背景。

返回值

(true)  完成后始终如实。

源文件

路径:wp-includes/taxonomy.php

<?php
...
function wp_update_term_count_now( $terms, $taxonomy ) {
	$terms = array_map('intval', $terms);
	$taxonomy = get_taxonomy($taxonomy);
	if ( !empty($taxonomy->update_count_callback) ) {
		call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
	} else {
		$object_types = (array) $taxonomy->object_type;
		foreach ( $object_types as &$object_type ) {
			if ( 0 === strpos( $object_type, 'attachment:' ) )
				list( $object_type ) = explode( ':', $object_type );
		}
		if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) {
			// Only post types are attached to this taxonomy
			_update_post_term_count( $terms, $taxonomy );
		} else {
			// Default count updater
			_update_generic_term_count( $terms, $taxonomy );
		}
	}
	clean_term_cache($terms, '', false);
	return true;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_update_term_count_now/