更新分类中的术语数量。
原型
wp_update_term_count( int|array $terms, string $taxonomy, bool $do_deferred = false )
描述
如果应用了分类法回调,则会调用它来更新计数。
参数
$terms
(int|array)
(Required)
术语的term_taxonomy_id。
$taxonomy
(string)
(Required)
该术语的背景。
$do_deferred
(bool)
(Optional)
是否刷新延期期限也很重要。
返回值
(bool)
如果没有条款会返回false,如果成功则返回true。
源文件
路径:wp-includes/taxonomy.php
<?php
...
function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) {
static $_deferred = array();
if ( $do_deferred ) {
foreach ( (array) array_keys($_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_merge($_deferred[$taxonomy], $terms) );
return true;
}
return wp_update_term_count_now( $terms, $taxonomy );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_update_term_count/