WordPress Media Library Search not working? Step-by-step solutions

Follow this step-by-step guide if your WordPress Media Library Search is not working.

As a long-time WordPress developer and publisher, I’ve encountered numerous instances where the Media Library search functionality fails to work as expected. This can be frustrating, especially when you’re in the middle of creating content.

In this article, I’ll discuss various potential causes and solutions for when your WordPress media library search does not work.

I am splitting this article into two parts. First, we are testing various ways to narrow down the scope of the issue. Second, we are trying to find out what is causing the WordPress Media Library search not to work.

First, let’s run through some checks to narrow the scope of a potential issue with the Media Library not working as expected.

Here are the quickest checks:

  • Look for the image in the frontend: If you remember where you embedded the picture in the frontend, check if it is still there. If not, you might have removed it after all.
  • Search for other images: If you find different images, the problem could only be with specific images or features of images. See also the next section about which data is included in the search.
  • Check the general WordPress search in the frontend and backend. If it is also not working, the search is broken on a higher level, not just for images. Some other code or a security feature likely causes it.

What the WordPress Media Search looks for

By default, WordPress considers several pieces of information when searching media:

The search does not consider the “content” of files, e.g., text in PDFs or images. IPTC copyright or caption information is also ignored.

Large Media Library

I have seen many websites with tens of thousands of images. In such cases, the search might take longer or, with limited hosting capacities, even break.

In that case, try to delete unused images.

Code errors

I usually install the Query Monitor plugin to identify if some of my custom code, a plugin, or a theme is causing the problem. It shows me any PHP errors and slow queries.

I also look at the debug.log file for any PHP issues Query Monitor couldn’t catch.

Finally, I open the Console in my Browser to look for JavaScript issues.

Test the REST API

Sometimes, the issue lies deeper in the WordPress REST API. Here’s how I investigate:

  1. Try accessing https://YOURSITE.COM/wp-json/wp/v2/media?search=SEARCH-TERM
  2. Replace YOURSITE.COM with your actual domain and SEARCH-TERM with a term you know should return results.
  3. If this returns empty results when it shouldn’t, there’s likely an issue with your REST API.

The REST API might be broken by any of these causes:

  1. A (security) plugin or custom code breaks or restricts REST API access.
  2. Review your .htaccess file for any rules that might be blocking API requests.
  3. Ask your hosting provider about potential server-level restrictions.
  4. Check the rules in your firewall, e.g., CloudFlare or Sucuri.net.

For more information, see the appropriate sections below.

Finding the cause

Find the file in the Media Library

Sometimes, the Media Library search might not find an image because you haven’t uploaded it yet.

To verify:

  1. Navigate to the Media Library in the WordPress admin panel.
  2. Test if you can find other images.
  3. Try various keywords associated with the not-found image.

You can also resolve to look for the image manually:

  1. Switch to the “List View” if you’re in “Grid View”.
  2. Scroll through or use the browser’s search function (usually Ctrl+F or Cmd+F) to look for the file.

To resolve:
If the file isn’t there, upload it to your media library.

External Media Services and CDN

If you’re using services to offload your media to external storage (like Amazon S3), a Content Delivery Network (CDN), or via an option in your hosting package, this could cause search issues.

To verify and resolve:

  1. Temporarily disable the offloading plugin or service.
  2. Try searching for media again.
  3. If it works, check the settings of your offloading plugin or contact their support for assistance.

Plugin Conflicts

Plugins quite often interfere with core WordPress functionalities. I have seen that happen a couple of times regarding search.

To verify and resolve:

  1. Deactivate all plugins (you can use the Health Check & Troubleshooting plugin).
  2. Test the media search.
  3. If it works, reactivate plugins one by one, testing after each activation.
  4. When you find a conflicting plugin, report the issue to the developer or look for an alternative.

To speed things up with plugin support, you could try to reproduce the issue on a test site, on which the support team can then ideally see and fix it. As a plugin developer myself, I’d very much appreciate that.

Theme Issues

Sometimes, themes can conflict with WordPress’s search, especially if they offer custom search features.

To verify and resolve:

  1. Switch to a default WordPress theme like Twenty Twenty-Four. You can also use the Health Check & Troubleshooting plugin for this.
  2. Test the media search.
  3. If it works, your theme might be the culprit. Contact the theme developer for support.

Custom Code

More than once, I broke the WordPress search using custom code. You or your developer should know best where they put it. If you don’t know, check in this order:

  • The theme’s functions.php file.
  • A custom plugin on the “Plugins” page in the WordPress dashboard.
  • Custom code is managed through a plugin like Code Snippets, which is usually accessed via a dedicated menu in the WordPress dashboard.

Custom code can be broken in as many ways as code in a third-party theme or plugin can be. Assuming that you, a colleague, or a service provider you hired was responsible, look for the following things:

  • Anything that manipulates the WordPress search, especially using the pre_get_posts filter.
  • Anything that restricts or manipulates the WordPress REST API.

Hosting Provider

I am very confident that the major hosting providers would not cause the WordPress media search not working unless you made some custom settings.

If they specialize in WordPress and you don’t have the necessary technical knowledge, you might still want to contact their support for some advice.

If your media search is working but very slow, here are some steps I take:

  1. Optimize the database: Use a plugin like WP-Optimize to clean up and optimize your database.
  2. Reduce media library size: Remove unused images to free up some space.
  3. Upgrade hosting: If you have a large site, you might need more robust hosting.

Conclusion

I have seen the WordPress Media Search not working a couple of times. In most cases, my custom code or another plugin caused this. Often, this also broke the general WordPress search.

By systematically working through the lists above, I’ve usually been able to resolve these media library search problems. Remember, if you’re uncomfortable making these changes yourself, it’s always best to consult a WordPress professional or your hosting provider’s support team.

Portrait of Thomas Maier, founder and CEO of Image Source Control

Questions? Feedback? How can I help?

Reach out directly via the contact form.