Sorry for the delay in replying. Thank you very much indeed vtxyzzy! This is exactly what I was looking for, the query works like a charm!
Here is how the final code became in functions.php, if any kind of help for further reference:
function restaurant_search( $taxonomy ) {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
$('#cidade').change(function(){
var cidade=jQuery('#cidade').val();
$.ajax({
url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
type:'POST',
data:'action=category_select_action&name=' + cidade,
success:function(results)
{
$("#cozinha").html(results);
}
});
});
});
</script>
<form action="<?php echo home_url('/'); ?>" role="search" method="get">
<?php // First dropdown
$term_selected_cidade = get_terms('cidade');
echo '<select id="cidade" name="cidade">';
echo '<option disabled="disabled" selected="selected">Cidade</option>';
foreach ($term_selected_cidade as $term) {
echo '<option id=' . $term->term_id . ' value=' . $term->slug . '>' . $term->name . '</option>';
}
echo '</select>';
?>
<!-- Second Dropdown -->
<select name="cozinha" id="cozinha" >
<option>Escolha uma cidade</option>
</select>
<input type="submit" value="buscar" />
</form>
<?php }
function implement_ajax() {
// Populates the second dropdown with cuisine terms
global $wpdb;
$cozinha_term = $_POST['name'];
$query = "
SELECT DISTINCT $wpdb->terms.name, $wpdb->terms.slug
FROM $wpdb->terms
INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id
INNER JOIN $wpdb->term_relationships ON $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id
LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->term_relationships.object_id
WHERE $wpdb->term_taxonomy.taxonomy='cozinha' AND $wpdb->posts.ID IN (
SELECT $wpdb->posts.ID
FROM $wpdb->terms
INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id
INNER JOIN $wpdb->term_relationships ON $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id
LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->term_relationships.object_id
WHERE $wpdb->term_taxonomy.taxonomy='cidade' AND $wpdb->terms.slug='$cozinha_term')";
$object = $wpdb->get_results($query);
$cuisine_terms = array();
for ($i = 0; $i < count($object); $i++) {
$cuisine_terms[] = get_object_vars($object[$i]);
}
echo '<select id="cozinha">' . '<option disabled="disabled" selected="selected">Cozinha</option>';
foreach ($cuisine_terms as $term) {
echo '<option value=' . $term['slug'] . '>' . $term['name'] . '</option>';
}
echo '</select>';
}
add_action('wp_ajax_category_select_action', 'implement_ajax');
add_action('wp_ajax_nopriv_category_select_action', 'implement_ajax');