Backfill a featured image on every post that lacks one

MediaAdvanced~30 minUpdated

Before you start

A connected site with content reads on and the upload-media and set-featured-image write abilities enabled. New images are fetched from HTTPS links and must be jpg, png, gif, or webp. The link must go straight to the image: a link that redirects is refused. Take a backup before a large run. The post list can filter by status, type and a search word but not by category, tag, date or an empty featured image, so the agent reads the posts and applies that rule itself. Each page returns at most 50 posts, so a large site takes many calls.

Featured images are the setting everyone skips when they are moving fast, and it shows up later as a wall of empty thumbnails on the blog index and blank cards when a post gets shared. Fixing it by hand means opening every orphaned post one at a time, and you lose the will to continue around post six.

This finds the gap for you, agrees on where the images come from, and fills it in reviewed batches. The finding is all reads. The filling is a write, so it stops for your approval before it sets anything.

The prompt
Help me backfill featured images across the site. Read only first: pull
the posts whose featured image is empty and tell me how many there are.
Do not set anything yet. Then let's agree on where the images come
from: for some I will point you at an existing image in the media
library, for others you will fetch a new one from an HTTPS link I give you
(jpg, png, gif, or webp). Show me a small sample that
pairs each post with the image you plan to use and wait for my
approval. Only after I say so, set the featured images in small
batches and pause between them so I can watch. At the end, list every
post you changed.

Why this is safe to run

The whole discovery pass is reads. Listing the posts and spotting the ones whose featured image is null writes nothing, so you learn the size of the job and see the exact list before a single image is set.

The write side is deliberately narrow and staged. Fetching a new image accepts only HTTPS links to jpg, png, gif, or webp files, so nothing odd enters the library; picking from existing media reuses images you already trust. Setting a featured image changes one reference on the post and never touches the body or the publish status, which is what makes it easy to undo: the Changes tab in wp-admin can revert each one for up to 30 days, unless that post was edited afterward. The uploads that feed it are not recorded, so fetched files stay in the library until you delete them. The work runs in small batches with a pause between each so a wrong turn is caught after a handful, not a hundred. The write abilities stay off until you enable them, every call is checked against the bound user’s capability, and every post the agent sets lands in the Activity Log so the closing list is verifiable.

Already connected? Skip the paste. Ask your agent for the “featured-image backfill” recipe, or just tell it to find the posts missing a thumbnail, and it runs the same reads-first, approve, then batch flow on your own site.

How it works

  1. List the posts whose featured image is empty and show you the count.
  2. Agree on where each image comes from: the media library or new uploads.
  3. For a library image, pick an existing attachment; for a new one, fetch it from its HTTPS link first.
  4. Show a small sample pairing each post with its chosen image, and wait.
  5. On approval, set the featured images in small batches, pausing between.
  6. Return the list of every post it changed.

Questions

How does the agent know which posts are missing an image?
get-posts returns each post's featured_image as null when there isn't one, so the agent filters on that. You see the list and the count before anything is set.
Is this reversible?
Yes, with one limit. A featured image is a single reference on the post, and setting one does not touch the post body or its status. If a choice is wrong you point the post at a different image, or remove it in the editor, because no tool clears a featured image. The Activity Log records every post that was set.