triple drop down for populating custom taxonomies

Without having some kind of relationship defined between the taxonomies its very hard to achieve and not scalable, meaning that you would have to:

  • catch the change of the state (first) dropdown and then get a list of
    all posts with that taxonomy term (first Query)
  • then loop over all posts and get the list of cities these posts are
    in (second query) avoiding duplicates and return that list

you would have to repeat that for the change of the cities (second) dropdown.

Now the problem here is with the second query which is actually lots and lots of small queries and there number will only grow. So that is what i mean not scalable.

A better solution would be to use one taxonomy with hierarchical structure where the top level terms are states, the second level terms are cities and the 3rd level are manufacturers, when you are set up in this way the flow becomes:

  • catch the change of the state (first) dropdown and then get a list of
    terms with that taxonomy term as parent (first Query) and return that list

that’s it but this also has a major con and that is the managing of the terms becomes a pain in the $%^ since you would have the same manufactures over and over in different cities.

Another Solution would be to use 3 different taxonomies but also create a custom database table for holding relationship between taxonomy terms.

And the last solution i can think of is using 3 different taxonomies and creating a custom SQL query to get the needed terms (which requires a major ninja like SQL skills that i sadly do not own 🙂 )

Once you figure out which road you are taking then it’s a simple matter of creating an ajax call on a change event and populating the next dropdown with the results.