»WordPress»Solution to WordPress Media Library's failure to search for attachments
Modify a code to solve the problem that WordPress background media library cannot be searched
preface
Some time ago, a friend said that using Git would cause the background media library to be unable to search, because I am here to automatically rename uploaded files, so I am not too impressed with this need, but actually I have probably had an idea, so I solved this problem some time ago and recorded it here.
Problem source
In fact, the problem mainly comes from the function of [Search Results Exclusion Page]. When you search Baidu, you will find that the code is similar to the following code
This code means that if you search, only the post article type is displayed, that is, the article has no page, but the problem is that this code has no limited location, which makes it possible to run in the background, and the background search is generally article search, but if it is attachment search, it is GG, so we need to modify this code.
The code modification is just to add an is_admin judgment, which is also very simple.
Postscript
Why is this simple problem almost undetected? First, Baidu's results are almost all wrong. In addition, no one has found this problem after the theme has been published for many years, which shows that this demand is very small. In fact, because Git automatically renames files, the method of searching file names is not a good attachment management method,The best way is to classify and label management. Cloudfall has recommended an attachment management plug-in for some time. Well, it's worth looking forward to.