After registering the article as a draft to WordPress, next set the category, tags, and eye catch. It only takes a few clicks on the admin screen, but with WP-CLI, if you don’t clarify which post to go to and whether to keep or replace existing settings, you may end up changing another article or removing a necessary classification.
In this article, we will check the existing categories and tags for one draft that has already been created, set only human-approved categories and images, and reread the results. The command examples are for a hypothetical environment.
- Roles you should know first
- What will change with this work
- Overall flow
- 1. Check the target post by ID
- 2. Read the current classification and eyecatches
- 3. Find existing categories and tags
- 4. set replaces existing classification
- 5. Check before sending images to the server
- 6. Incorporate only one eye-catching image
- 7. Reread the setting results
- 8. Preview on the management screen
- Do not perform continuous operations when failure occurs
- Request to AI
- Example of completion report
- Summary
- Reference materials
Roles you should know first
Category
Articles are categorized by major themes to make it easier to navigate the site. Since it has a hierarchy, it is also possible to have a configuration where “AI site management” is placed under “for the host”.
Rather than attaching many categories to one article, you can decide from which point readers will search for the article. Please prioritize the operation rules for each site.
Tag
A supplementary summary of topics that span multiple categories. If you create a large number of similar notations, the number of thin list pages with only one article will increase. The basic rule is to avoid duplication such as “WordPress”, “WordPress”, and “WP”, and choose from existing tags.
Eye catch
Used as a representative image in article lists, SNS sharing, related articles, etc. This is different from inserting an image into the body of the text. Simply registering an image to the media library will not make it an eye-catcher for your article.
Alternative text
This is a text that conveys the content to users who cannot view the image. Concisely explain the purpose of the image, and don’t unnaturally stuff it with article titles or search terms. This will be handled differently than an image that is just for decoration, but if it is an eye catch that explains the content of the article, it will convey what is depicted.
What will change with this work
- Relationship between target post and category/tag
- Attachments in the media library
- Meta information such as alternative text for images
- Featured image ID of the target post
- Depending on the theme, article list or preview display
The database and media area will change even if it is a draft. If you import an image by mistake, it will remain in your media library even if you remove it from the post. Fix the target ID, image file, and existing settings before execution.
Overall flow
Check the target draft ID
↓
Read current categories, tags, and eyecatches
↓
Human selection from existing classification candidates
↓
Check image rights, content, size, and alts
↓
Set to only one target
↓
Reread classification, attachment ID, eyecatch ID, alt
↓
Preview and stop on the management screen
1. Check the target post by ID
Use the post ID returned in the previous article. You cannot decide what to change just by searching the title.
wp post get 123 \
--fields=ID,post_title,post_name,post_status,post_type \
--format=json
Stops if the following does not match.
- Post ID is as expected
post_typebecomespostpost_statusbecomesdraft- Title and slug match the target manuscript
If the article is already published, the steps in this article will not change it. Changing the classification of published articles also affects listings and search engine traffic and requires separate approval.
2. Read the current classification and eyecatches
Record the state before the change.
wp post term list 123 category \
--fields=term_id,name,slug,parent \
--format=json
wp post term list 123 post_tag \
--fields=term_id,name,slug \
--format=json
wp post meta get 123 _thumbnail_id
If eyecatch is not set, retrieving _thumbnail_id may result in no value or an error. On the wrapper side, it is necessary to have a design that treats “Not set” as a normal confirmation result and does not interrupt the entire process by mistake.
The output will be left in the execution record. If you later discover an unintended replacement, you can check the original category, tag, and image ID.
3. Find existing categories and tags
First, list the candidates that exist on the site. Limit the number of items and output items.
wp term list category \
--fields=term_id,name,slug,parent,count \
--number=20 \
--orderby=name \
--order=asc \
--format=table
wp term list post_tag \
--fields=term_id,name,slug,count \
--number=20 \
--orderby=name \
--order=asc \
--format=table
This example limits categories and tags to a maximum of 20 each. Without --number, --fields and --format=table alone do not limit the number of results. Do not conclude that a classification does not exist just because it is missing from these 20 results. Check additional results and candidates through administrator-approved pagination or filtering by name or slug. Do not create a new classification until this check is complete.
Humans check the article plan and existing category structure instead of having AI choose just the name. Also check parent and term_id, as categories may have child categories with the same name under different parents.
New classifications are not automatically created in this process.
When there are no candidates, classifications will multiply if AI automatically creates similar tags and categories. When establishing a new facility, consider the following separately.
- Is there already a classification with the same meaning?
- Will it be used in multiple articles in the future?
- What to do with slug and display name
- Where to set the parent category
- Whether to search the category list
This article uses only existing, approved classifications.
4. set replaces existing classification
WP-CLI official wp post term set replaces the value of that classification on the target post. It does not mean “add one”.
For example, if you run the following without checking the current category, the previously attached category may be removed.
wp post term set 123 category ai-site-management --by=slug
If your site also explicitly attaches parent categories to articles, specify all approved categories at once.
wp post term set 123 category 40 41 --by=id
Here, 40 and 41 are fictitious term IDs. We will check the actual ID in advance and approve it, including the order and number of items. For hierarchical categories, it would be easier to use IDs to avoid confusion between names with the same name.
If the tag is set, it will replace the existing tag.
wp post term set 123 post_tag wp-cli wordpress-operation --by=slug
If you need to “keep existing tags and add only one”, there is another operation called wp post term add.However, in the AI wrapper, it will be easier to verify if the behavior is not increased too much, and if it is unified to “Check the list before change and replace it with the approved final state.”
5. Check before sending images to the server
Humans check the following for image files:
- The image is an image that you have taken or created yourself, or that meets the usage conditions.
- Guest’s face, car number, reservation information, etc. are not shown.
- This is not a composition or presentation that could lead to misunderstandings about cats or facilities.
- Representative of the content of the article
- File format and capacity are within the site operation rules
- File name is descriptive and does not contain confidential information or personal names
- Alternative text describes the content and purpose of the image
When using image generation AI, it is important not to misidentify the image as a photo of an actual facility. If it’s an article introducing a facility, you’ll need to decide to give priority to actual photographs that have permission.
6. Incorporate only one eye-catching image
WP-CLI’s wp media import imports images into the media library, and --post_id allows them to be associated with posts. If you specify --featured_image, it will also be set as an eye catch for that post.
wp media import approved-featured-image.webp \
--post_id=123 \
--title="記事を説明する画像タイトル" \
--alt="宿主が記事の分類と画像を確認するイラスト" \
--featured_image \
--porcelain
Record the attachment ID returned by --porcelain.
AI will not be able to freely specify any local file or URL.In a dedicated wrapper, restrict as follows:
- Only 1 file in the allowed image folder
- Limit allowed extensions and maximum capacity
- Reject paths and external URLs containing
.. - Targets only approved draft IDs
- Fixed
--post_id,--featured_image,--porcelainon the processing side - Do not execute if alt is empty
- Do not accept multiple files at once
If you import directly from an external URL, the source or content may have changed later. Place it in your permissions folder and check its contents and rights before using it.
7. Reread the setting results
Don’t judge success just by the command’s exit code, check from the target post.
wp post term list 123 category \
--fields=term_id,name,slug,parent \
--format=json
wp post term list 123 post_tag \
--fields=term_id,name,slug \
--format=json
wp post meta get 123 _thumbnail_id
Check whether the returned eyecatch ID matches the attachment ID recorded when importing the image. Next, read the attachment itself.
wp post get 456 \
--fields=ID,post_title,post_mime_type,post_parent,guid \
--format=json
wp post meta get 456 _wp_attachment_image_alt
Here 456 is a fictitious attachment ID.Check the following items:
- Target post ID has not changed
- Category matches final approved list
- Tag matches final approved list
- Previously required classifications have not disappeared unintentionally.
- Eyecatch ID and attachment ID match
- MIME type is the expected image format
- Alternative text is not empty and matches the content
- Remains in draft state
8. Preview on the management screen
Finally, the person opens the draft in the admin screen.
- Eye-catches are cropped as intended at the top of lists and articles.
- Images are not too large or blurry on smartphones
- Text in images is not difficult to read
- Category/tag display position and link destination are correct.
- Posted as intended in existing category list
- Poster and description have not changed.
- Article has not been published yet
Depending on the theme, eye-catches are automatically displayed at the top of the text. If you place the same image within the main text, it may be displayed twice, so please check.
Do not perform continuous operations when failure occurs
Even if the image import times out, the image may actually be registered in the media library. If you immediately rerun the same command, you will get multiple identical images.
If it fails, check in the following order.
- Check
_thumbnail_idof the target post - Check the attachment ID returned just before.
- Check the file name and registration time in the media list
- Reread the current classification values
- Report the current situation to someone and stop it.
Removal of duplicate media is not included in this process. Perform a separate task that confirms the deletion target and usage locations.
Request to AI
Please set the category, tags, and featured image to draft post ID 123.
Before execution:
- Check post ID, title, slug, post_type, post_status
- Record current category, tag and _thumbnail_id
- Show suggestions from existing categories and tags
- Do not create new categories or tags
- Check the image file name, format, capacity, alt, and usage conditions
- Shows before and scheduled changes, and stops until someone approves
At runtime:
- Target only one approved draft
- Set categories and tags to final approved list
- Import only one image from the allowed folder
- Use --featured_image and record attachment ID
- Not published. Do not change or delete other articles or existing media
After running:
- Reread categories, tags, _thumbnail_id, attachments, alts
- Ensure post_status remains draft
- Report and stop items that people see in the preview
Example of completion report
Draft settings result
- Target: Post ID 123, example-article
- Status: Maintain draft
- Category: Checked before and after changes
- Tag: Checked before and after changes
- Eyecatch: Attachment ID 456
- alt: Set and reread
- New classification: Not created
- What hasn't changed: other articles, existing media, publication status
- Next operation: People preview on the admin screen
Summary
When setting categories, tags, and eyecatches, first check the target draft ID and the state before changes. wp post term set replaces existing classifications, so it is important to pass the final approved list and read it again after configuration.
After checking the rights, personal information, content, capacity, and alternative text of the image, import only one image and check that the attachment ID and _thumbnail_id match. For how to create a draft, go to How to register only one article as a draft, for restrictions, go to WP-CLI limited wrapper, and for the process after human approval, go to Article publication and display confirmation.
Reference materials
- WordPress Developer Resources:wp post term list
- WordPress Developer Resources:wp post term set
- WordPress Developer Resources:wp term list
- WordPress Developer Resources: term result limits in WP_Term_Query
- WordPress Developer Resources:wp media import
- WordPress Developer Resources:wp post meta
Note: Depending on the theme or plugin, additional processing may be performed when classifying or saving images. Start with a test environment and one draft.
Note added on 2026-10-09: The term candidate lists now include explicit result limits, and the article clarifies that absence from a limited list does not establish nonexistence. The original full-article information check date remains 2026-08-16.

