im developing a logic for populating 3 custom taxonomies into 3 drop downs, i have a custom post type dealers and under that i have 3 taxonomies
1. State
2. City
3. Manufacturer
when i select the state i have to populate the cities that are related to the state, and when i select the city and i have to populate the manufacturers list in the 3rd drop down that is related to the city that i have selected… This is the example link that i am working on
here is the code for displaying the custom tax in drop down
<li id="categories">
<h2><?php _e('Locate Dealer'); ?></h2>
<form action="<?php bloginfo('url'); ?>" method="get">
<div>
<?php $state_args = array('taxonomy' => 'state', 'hide_empty' => 0, 'depth' => 2); ?>
<?php wp_dropdown_categories($state_args); ?>
</div></br>
<div>
<?php $city_args = array('taxonomy' => 'city', 'hide_empty' => 0); ?>
<?php wp_dropdown_categories($city_args); ?>
</div></br>
<div>
<?php $man_args = array('taxonomy' => 'manufacturer', 'hide_empty' => 0); ?>
<?php wp_dropdown_categories($man_args); ?>
</div></br>
<input type="submit" name="submit" value="view" />
</div>
</form>
</li>
can anyone help me for filtering the data…… im not a pro in WP, plz bare with me.
thanks in advance
Without having some kind of relationship defined between the taxonomies its very hard to achieve and not scalable, meaning that you would have to:
all posts with that taxonomy term (first Query)
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:
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.