Alright, so first, I need you to check out this wire-frame so you can see what I’m trying to accomplish:
What I’ve done so far is this:
- I created a custom post type for individual addresses.
- I created a hierarchical custom taxonomy where the “parent categories” are States, and the “child categories” are Cities.
-
I’ve used the following code to populate the first select element:
<select name="states" id="states" class="etc"> <?php $terms = get_terms('area', 'parent=0'); $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { echo '<option value="' . $term->name . '">' . $term->name . '</option>'; } } ?> </select>
So here’s what I need to know:
- How do I populate the second select element based on which parent is selected in the first?
- How do I use these select elements to filter my custom posts?
Are you familiar with jQuery? You’ll want to post the term to a admin-ajax, and use the response to populate the second select.
Here is the codex documentation:
http://codex.wordpress.org/AJAX_in_Plugins
A loose example for your situation:
You would build the options in a similar way as you have show in your AJAX response callback, so that that is what is returned and is what is appended to the City select.
Note the “Ajax on the Viewer-Facing Side” section of the above codex link to make sure it works for non-loggedin users.