When a bot drafts a lot of posts a day, it falls into a rut and keeps grabbing the same three header images. Here’s the small fix I use: a list of approved images tagged by pillar, a lookup of their WordPress media IDs, and a check against recent batch logs so it picks something fresh.
1. Keep an approved list with a pillar
Only images you’ve cleared (CC0 or your own) go in. Each one gets a pillar like God, Linux, AI or Tech. Name files by pillar, like god-cross.jpg or tech-server-hall.jpg, and the matching is easy.
2. Map files to media IDs
The REST API’s media endpoint gives you each ID and its file URL:
source ~/.config/wordpress/site.env
curl -s -u "$WP_USER:$WP_APP_PASSWORD" -G \
"https://example.com/index.php?rest_route=/wp/v2/media" \
--data-urlencode "per_page=100" \
--data-urlencode "_fields=id,source_url" > media.json
3. Skip what recent batches used
Every run already writes a small JSON batch log with each post’s featured_media. Read the last few and pick the first approved image for the pillar that isn’t in that set:
import json, glob
media = {m["source_url"].rsplit("/", 1)[1]: m["id"]
for m in json.load(open("media.json"))}
used = set()
for f in sorted(glob.glob("drafts-*.json"))[-4:]:
used |= {p["featured_media"] for p in json.load(open(f))["created"]}
def pick(pillar):
for name, mid in sorted(media.items()):
if name.startswith(pillar + "-") and mid not in used:
used.add(mid)
return mid
return None # ran out: reuse the oldest, but flag it
print(pick("god"), pick("tech"))
4. Verify it stuck
After you create the draft, read it back and make sure featured_media is the ID you set. If it isn’t, log a failure. Don’t just assume.
It’s a tiny thing, but a front page where every post has the same header looks lazy. A few lines of code fix it.
Have a blessed day! And Happy Hacking!