I believe what you’re looking for is called “Faceted search”, i.e. the ability for people to not only input a search query, but also to filter it down by other existing criteria (categories, tags, etc).
I actually just recently built this functionality for a client of mine — a real estate company — so it’s *fairly* fresh for me. But, since it was my first time doing something like this, I’m pretty sure that my code isn’t as clean as it could/should be.
The basic outline of what you’ll need:
1. Search box – this contains all of your custom variables. Whether they’re drop downs, check boxes, or links — mine were all hard-coded as check boxes with unique IDs
2. Custom search results template – This is the other end; once the search form gets submitted, your search results page has to interpret the variables you passed through to determine how to filter it all down.
Now, the best way (that I found) to accomplish all of this is just by passing the variables using a GET/POST method, and then interpreting these inputs on the other side.
Like I said, my code is all done by hand and probably not the most efficient, but here’s what I did.
Search box:
[Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]
As you can see, I also used the GET method here to figure out whether that variable had already been passed in on that page, and then check it if it had (so they wouldn’t have start fresh if they just wanted to change one variable).
Further down, I created a loop and passed in the variables (again, this got super complex/tedious because of the way it had to function and that when CERTAIN boxes were checked, it meant I had to exclude parallel categories, but OTHER boxes were independent).
Here’s me interpreting all of the variables and putting it together to figure out which categories to look in:
[Code moderated]
Like I have said multiple times, I may have SEVERELY over-complicated this solution. But, given my limited knowledge, I had to sort of hack it together. It works well, even though the code may not be the prettiest or well-optimized.
Here’s the site for reference: https://rentinia.com/property-search?area=3&price=4&type=16&tag-dropdown=Any+Bedrooms&formSubmit.x=236&formSubmit.y=18&formSubmit=submit
If you have any specific questions, I’ll try to help the best I can.
-T
EDIT: Oh, one more thing: I was also working with an EXISTING search functionality from another page template that was built on drop downs. So, that’s why there are a lot of redundant options (you’ll notice I’m looking for both numerical values as well as text-based values in a lot of cases).
Unfortunately, I didn’t really have the ability to retroactively change the values from the existing drop down search, so I just had to patch it in and make it all work together.