This is a trick that has been useful to me many times, especially when I have had to import data from some other source. In this example the function retrieves all the taxonomies that are not those integrated into WordPress, but only the customized ones. By changing the _builtin parameter of get_taxonomies from false to true, the same function can also be used for categories and tags.

Enjoy.

/**
 * Update post count for all taxonomies.
 */
function wporg_update_taxonomies_count() {
	
	$taxonomies = get_taxonomies( [
		'public'   => true,
		'_builtin' => false

	], 'names', 'and' );

	foreach ( $taxonomies as $taxonomy ) {

		$get_terms_args = [
			'taxonomy'   => [ $taxonomy ],
			'fields'     => 'ids',
			'hide_empty' => false,
		];

		$update_terms = get_terms( $get_terms_args );
		wp_update_term_count( $update_terms, $taxonomy );
	}
}

add_action( 'init', 'wporg_update_taxonomies_count' );