Update WordPress taxonomy counts
<p>I have a site with 400+ posts (using categories) and also 200 products (using a number of custom taxonomies). Somehow the count has got messed up and I can only seem to fix one or the other.</p>

<p><a href="https://stackoverflow.com/questions/18669256/how-to-update-wordpress-taxonomiescategories-tags-count-field-after-bulk-impo">The first answer here</a> fixes the categories but breaks the custom taxonomies, and the second answer fixes the custom taxonomy count but breaks the category count.</p>

<p>What SQL query do I need to fully count and update all taxonomies for all post types?</p>