I’ve googling for a solution for this issue and found nothing: I have some posts from a Custom Post Type (Restaurants) and its taxonomies (‘city’ and ‘cuisine’). Whenever I create a restaurant post, I can set many ‘cuisine’ terms as I want, but ‘city’ is single selected. I’ve also made a custom search using a html dropdown which I can search from ‘restaurants’ posts by filtering from its taxonomy terms.
The search works well but what I really want is populate the second taxonomy (cuisine) only with terms that has some relationship based on the first taxonomy chosen (city). In the first dropdown, if someone choose the city ‘New York’ the second dropdown must display only cuisine terms that has relationship with ‘New York’ city term on restaurant posts. If there’s not a post with ‘brazilian’ cuisine and ‘New York’ city registered, the ‘brazilian’ term must not appear on second dropdown. Of course, the cuisine dropdown doesn’t have to display duplicated terms.
Is that possible? Thanks in advance!
Here’s part of the answer… how to query for the terms you’re looking for. But it sounds like you’ll need some ajax to re-query for each selection.
City and cuisine would be dynamic, but essentially the when the user selects the city populate that data into the
$city
variable, and so on.Someone else will need to chime in with the ajax part.
Sorry for the long delay in replying, but thanks for your help guys, it’s good reference!
vtxyzzy from wordpress.org forum help me with the query part, the ajax and php did myself, don’t know if it’s neat. Here is how the final code became in functions.php: