brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp term list shows every WordPress category or tag with its post count

WordPress
~/tips/tip-wordpress-term-list-count

wp term list post_tag --fields=term_id,name,slug,count

Lists the terms of a taxonomy with ID, slug and how many posts use each one.

Tags pile up. The Tags screen pages through them twenty at a time, the terminal shows them all at once.

wp term list post_tag --fields=term_id,name,slug,count

The first argument is the taxonomy: category, post_tag, or a custom one such as product_cat. count is the number of posts that use the term.

To find tags nobody uses, sort the CSV output in the shell:

wp term list post_tag --fields=term_id,name,count --format=csv | sort -t, -k3 -n | head

The ones at the top with a count of 0 are candidates for cleanup. Other filters come from get_terms(), so --parent=0 limits categories to the top level, and --field=slug prints only slugs, handy for a loop.

Two things I’d keep in mind. The count only covers published posts of the post types that use the taxonomy, so a term that only has drafts still shows 0. And names with a comma in them confuse the CSV sort above. For anything serious, use --format=json and jq.

Further reading: wp term list

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link