wp_update_term_count_now

函数
wp_update_term_count_now ( $terms, $taxonomy )
参数
  • (array) $terms The term_taxonomy_id of terms to update.
    Required:
  • (string) $taxonomy The context of the term.
    Required:
返回值
  • (true) Always true when complete.
定义位置
相关方法
wp_update_term_countwp_update_comment_count_nowwp_update_user_counts_update_post_term_countwp_update_network_counts
引入
2.5.0
弃用
-

wp_update_term_count_now是一个立即更新术语计数的函数,而不是把它安排在以后更新: 该函数用于需要立即更新术语计数的情况,而不是等待下一次预定更新。

立即执行术语计数更新。

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 ( array_filter( $object_types, 'post_type_exists' ) == $object_types ) {
			// 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;
}

常见问题

FAQs
查看更多 >