Backfill a featured image on every post that lacks one

MediaAdvanced~30 min

Before you start

A connected site with content reads on and the upload-media and set-featured-image write abilities enabled. Uploads must be jpg, png, gif, or webp. Take a backup before a large run.

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 upload a new one from a file I give you
(jpg, png, gif, or webp, read as base64). 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. Uploading pulls only from jpg, png, gif, or webp data, 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 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, upload from base64 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. 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 clear or change it, and the Activity Log records every post that was set.