Wordpress - Fixing category count
If you just want to update the counts of posts in each term, wp_update_term_count_now( $terms, $taxonomy )
should do it... just pass the terms affected as an array and run it once for each taxonomy you have.
You can also call wp_defer_term_counting( true )
before inserting new rows, and then after adding your posts, catch up on the counts by calling wp_defer_term_counting( false )
.