Dropdown: Display terms from B only if has relationship with a term A selected

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.

<?php

    $city = array( 'dallas' );
    $cuisine = array( 'italian', 'mexican', 'french );

    $args = array(

        'post_type' => 'restaurant',
        'posts_per_page' => -1,
        'tax_query' => array(
        'relation' => 'AND',
             array(
                'taxonomy' => 'city',
                'field' => 'slug',
                'terms' => $city
            ),
            array(
                'taxonomy' => 'cuisine',
                'field' => 'slug',
                'terms' => $cuisine
            )
        )
    );

?>

Leave a Comment