• diss0nance

    (@diss0nance)


    I am looking for an advanced search form, like the one on this page

    http://www.abercrombiekent.com/ (see the area Find the Perfect Holiday)

    I’ve been searching for a plugin or hack and not sure if I’m describing it right…

    is it a filtered search? dynamic query search?

    I’ve seen the multiple category select plugin… and I guess I can start there, but if you have seen something like this somewhere Please Help!

    thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • abovegrnd

    (@abovegrnd)

    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: http://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.

    Thread Starter diss0nance

    (@diss0nance)

    thank you for your response…

    I found a plugin called “cat + tag filter” http://wordpress.org/extend/plugins/cat-tag-filter-widget/

    It works for me, since I don’t really want visitors to search for something random, just select from the categories and tags and display associated posts.

    I will try to modify the plugin with your code and see if I can manage to add a second category filter…

    thanks again for your help

    abovegrnd

    (@abovegrnd)

    Glad I could help.

    I thought about doing it with a plug in as well, but I felt like it would be MORE work to customize something existing to have the level of control I needed, rather than to just code it all by hand.

    I also have a tendency to do things the hard way just because I like the challenge. J

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘filtered search by category’ is closed to new replies.