Tutorial: Use WP CLI to recount WordPress taxonomy terms

Tutorial: Use WP CLI to recount WordPress taxonomy terms featured image

Sometimes in WordPress or WooCommerce website, you find that (for example) some custom post type or other content has been removed, but the taxonomy terms are still registering the “old” content, and therefore the term numbers are all wrong.

Well, heck, what to do?!

In this situation, there are a few steps you can take in the MySQL database side to clean things out, which I won’t cover here, to keep this post on task. But let’s say you’ve done some clean ups, but you still think your category numbers are “wrong” or your tags show content which you know is really… gone.

WP CLI is your friend. This is the WordPress Command Line Interface.

The following command in WP CLI will get your categories and tags recounted:

wp term recount category post_tag

You can recount custom taxonomies too, for example, to recount WooCommerce product categories, you could use:

wp term recount product_cat

You’ll need to have installed WP CLI in your server (or use a good WooCommerce host which offers this out of the box) and be logged in via SSH terminal to run the above command, all of which are outside of the scope of this tutorial. If you’d like to find out more about how to do this, then leave a comment below requesting a tutorial!

Leave a Reply

Your email address will not be published. Required fields are marked *

Silicon Dales