thomasmery/woocommerce-recordstore

Add support for recounting taxonomy terms for Products

thomasmery opened this issue · 0 comments

We need a way to simply recount the terms associated with the store products

and thus accurately reflect the number of products associated with a term (in the term lists for instance)

this could be accessed via a button on the plugin dashboard

the function that would perform the operation is something along the lines of :

// trying to accurately reflect the nuber of products linked to the custom taxonomies terms
function update_terms_count( $taxonomy ) {
	global $wpdb;
	// we need a list of term_taxonomy_id
	// not of term_id
	// because the terms count update function needs this
	$taxonomy_terms_ids = $wpdb->get_col("
		SELECT tt.term_taxonomy_id FROM wp_term_taxonomy AS tt WHERE tt.taxonomy IN ('$taxonomy')
	");
	wp_update_term_count_now(  $taxonomy_terms_ids, $taxonomy );
}