Search for files


Yes, just put it in a file in your plugins folder (e.g. functions.php or methods.php, whatever you want to call it), then it is accessible from anywhere.

Let me know if you get the expected results. You can use the parameters just like in the pages search method, i.e. limit the fields to search in etc.


Texnixe, the result is really great.
The search goes through the text files and get pictures as results.
Thank you very much for your help.

I’m trying now to filter the results.
Exemple: if you make a search with the keywords :“blue” and “round”, it displays only the files having the two keywords into the text file.

Do you have an idea about how can I get such a result?


With the current function, that is not possible, unless you take apart the query string and then search for the first word and then search for the next in the results of the first, which is probably not very performant. Otherwise you would have to rewrite the function.

But what exactly is your use case? Maybe there is a better way to achieve what you want to do, maybe by filtering stuff.


I setting up a search bar, able to look through files and display results based on request.
So it goes through the text files of the files and look for keywords (you made this and it works great).
And ultimately when the user put two keywords into the search bar, let say “blue” and “big”, the result displayed is all the files containing the two keywords. It does not display the files containing only blue or big as keywords.
Only the files who have both keywords into their text files.

But maybe I should try to generate a JSON from the text files and look into with JS in order to display the result.

Thanks again for the conversation and your help!


That’s an option. But you could also adapt the PHP search function above in such a way that it does not loop through single fields but uses all text fields as a single unit, and change the regex to not use “OR” but “AND”.


Ok, could you explain me a bit how to do that?
I mean to loop through all the fields as a single unit?
(sorry to ask so much still learning php).

thank you