Find an image by its filename or alt text

MediaBeginner~3 min

Before you start

Plugin version 1.7.4 or newer, since earlier versions matched the title only. The two media read abilities enabled, on a connection bound to a user who can read the media library.

You know the image exists. You uploaded it, you can picture it, and you have no idea what it is called. The media library gives you a search box that, until recently, only looked at titles, and nobody edits the title of an uploaded image. So you scroll.

The 1.7.4 media search fixed the thing that made this frustrating. It now matches the filename and the alt text as well, which is where the real detail about an image actually lives. This prompt uses that, and it changes nothing.

The prompt
I am looking for an image in the media library and I only half remember it.
Read only, change nothing.
Search the library for [conference]. The search matches filenames and alt text
as well as titles, so try the fragments I can actually remember: bits of the
filename, and words someone would plausibly have written in the alt text.
If the first search comes back thin, try [2024] and [keynote] as separate
searches rather than giving up.
For anything that looks close, read the item in full and tell me its caption,
its dimensions, its file size, and what it is attached to. Then give me your
best match with its URL and id.
List the near misses too, with one line each on why you ruled them out. I would
rather see a wrong guess than be told there is nothing.

Why this is safe to run

Both abilities are reads. The list returns matching items with their URL, alt text, mime type, and dimensions plus the full match count; the single-item read opens one attachment for its caption, description, date, filesize, parent, and image sizes. Neither can rename a file, rewrite alt text, or delete anything.

The reason this works better than it used to is worth being precise about. Before 1.7.4, media search went through core’s standard search parameter, which matches the post title. An uploaded image inherits its title from the filename and then nobody touches it again, so the searchable text was whatever the file happened to be called at upload, and only that. From 1.7.4 the search also matches the stored filename and the alt text. Alt text is the useful half: it is written by a person, describing what is actually in the picture, for accessibility reasons that have nothing to do with search. Now it is searchable too.

Ask for the near misses as well. A search that comes back empty tells you very little, since the image might not be there or your fragment might simply be wrong. Three wrong images tell you the library is being read properly and your guess needs adjusting.

Already connected? Skip the paste. Ask your agent for the “find an image by its filename or alt text” recipe, describe what you remember, and it runs the same reads against your own library.

How it works

  1. Search the media library on whatever fragment you can remember.
  2. Try a second fragment if the first one comes back thin, since filename and alt text are both searched.
  3. Read the promising items in full to see caption, dimensions, and where each file lives.
  4. Pick the match and get its URL and id back.
  5. Report near misses too, so you can tell a wrong match from no match.

Questions

What exactly does the search look at now?
As of 1.7.4 the media search matches the stored filename and the alt text, along with content and excerpt. Before that release it matched the title only, through core's standard search parameter, which is why an image called hero-banner-final-v3.jpg was effectively unfindable unless someone had typed a matching title at upload time.
Why does the filename matter more than the title?
Because almost nobody edits the title of an uploaded image. WordPress derives it from the filename at upload and there it stays, so the real distinguishing text (the client name in the filename, the description someone wrote into the alt attribute for accessibility) was exactly the text the old search could not reach.
Can it change the image once it finds it?
Not with this recipe. Both abilities are reads: one lists matching items with their URL, alt text, mime type, and dimensions, the other opens a single item for its caption, description, filesize, parent, and image sizes. Editing alt text or captions is a separate write ability with its own gate.