How-Tos

How-To: Find Unused and Look-Alike WordPress Tags With WP-CLI

Leave a comment

After a few months of daily posting, my tag list on this site has grown into the hundreds. Before adding more, I like to check for tags nothing uses and near-duplicates that should probably be one tag. WP-CLI makes that quick, and all of this is read-only.

1. Tags with zero posts

wp term list post_tag --fields=term_id,name,count --format=csv | awk -F, 'NR>1 && $NF==0'

2. Your most-used tags

wp term list post_tag --orderby=count --order=desc --number=20 --fields=name,count

3. Names that only differ by capitalization

wp term list post_tag --field=name | sort -f | uniq -di

That catches things like “macOS” vs “MacOS.”

4. Look at one tag before touching it

wp term get post_tag 123 --fields=term_id,name,slug,count
wp post list --tag_id=123 --post_status=any --fields=ID,post_title,post_status

Swap in a real term ID from step 1 or 3.

Notes

  • The count only includes published posts. A tag used only on drafts shows 0, so check step 4 before deciding it’s unused.
  • Back up first if you do clean up: wp db export.
  • Merging or deleting tags changes URLs, so add redirects for any tag archive pages that get traffic.

God Bless, and Use the Source!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.