I have a bash script that posts to WordPress. It does this fine, but I want to have it add tags to the posts. It uses WP-CLI and there doesn’t seem to be a way to add tags to a post from it.
To clarify, I’m talking about post tags, not HTML tags.
Also, this bash script is being run on the same server that is hosting the WordPress site.
I also found blogpost.py, however it doesn’t seem to have a tag feature either.
From what I’ve read, I think I would be able to accomplish what I want using XML-RPC in some way, but I know almost nothing about it.
Here’s the WP-CLI command I’ve been using. Which works, but doesn’t add tags.
wp post create --post_title="This is the title" --post_content="This is the post" --post_status=future --porcelain
In desperation, I tried adding --post_tags="these are tags"
, but it didn’t work. I’ve been searching for the answer for days now.
I just want to be able to make a WordPress post, with tags and a category, from a cronjob. I’m familiar with bash, so that would be best, but if you know of any solutions using other languages, that’s welcome also.
Thanks.
As you may know, post tags are a WordPress taxonomy (like categories) called
post_tag
.You need a set of subcommands of
wp post
, specificallywp post term
, to edit them.You also need WP-CLI v0.18.0 or above â older versions don’t have it.
In all these examples, 1 indicates the post ID.
Add one or more tags to any existing tags
Separate multiple tags with spaces (not commas.)
“Set” one or more tags
This will replace (overwrite) any existing tags for the post.
You’d use this instead of
remove
followed byadd
(one fewer command necessary.)Separate multiple tags with spaces.
List current tags
Remove tag(s)
You can also use this for categories or any other taxonomy.
This can now be done more simply. In today’s latest version of wp-cli (2.4), tags_input is an option of wp post create and update. You can therefore use
or