So recently I moved a client from Blogger to WordPress.

When the posts imported from blogger, it saved the blogger “labels” as “tags” in WordPress. Since I’d like to have these as categories instead, I used a plugin to convert all tags to categories.

This worked fine and dandy, but it left Uncategorized on all of my posts. So now I have around 900 posts that all have their correct categories attached, as well as “Uncategorized”.

So my goal is to remove “Uncategorized” from all 900 posts, but I’m struggling to find a speedy method to do this.

Does anyone know how I could accomplish this in a bulk method?

6 s
6

With wp-cli installed you can run a bash script like this to remove the ‘uncategorized’ category from all posts with more than one category

#!/bin/bash

for post in $(wp post list --field=ID)
do
  count=$(wp post term list $post 'category' --fields="name" --format="count")
  if [ "$count" -gt "1" ]
  then
    wp post term remove $post category 'uncategorized'
  fi
done

Save this as something like delete_uncategorized.bash and then run bash delete_uncategorized.bash from the command line.

Tags:

Leave a Reply

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