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 post term add tags a WordPress post without opening the editor

WordPress
~/tips/tip-wordpress-post-term-add

wp post term add 123 post_tag docker

Adds a category or tag to a post from the terminal and keeps the terms it has.

Adding one tag to fifty old posts is a dull afternoon in the editor. In the terminal it is one loop.

wp post term add 123 post_tag docker

The arguments are the post ID, the taxonomy and one or more term slugs. add appends: the post keeps the tags it already had. If the slug does not exist yet, WordPress creates the term. Use --by=id when you’d rather pass term IDs.

For many posts, combine it with wp post list:

for id in $(wp post list --s=docker --field=ID); do
  wp post term add "$id" post_tag docker
done

That tags every post whose text mentions docker. Check the list first by running the wp post list part on its own, because search matches more than you expect.

Its sibling wp post term set looks almost the same, but it replaces all terms of that taxonomy on the post with the ones you give. Mix them up and you wipe the existing tags. I’d stick to add unless replacing is really what you want. wp post term remove takes one off again.

Further reading: wp post term add, wp post term set

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