-1
Personal I have 2 custom taxonomies in a post, are they, City and States. But I only want to use the taxonomy Cities and every city put her being Ascendant of their respective State. Once this is done I would like to make these 2 selects work as follows: first Select would give me the Status options and the Second Select the City options according to the selected State! I have these code below, but I don’t quite know how to do that I need. Here also is an image of how today is this select: https://prnt.sc/vz0r92
<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="filter">
<div class="row">
<div class="col-md-3 estados">
<?php
$taxonomy = 'estados'; ?>
<?php $terms = get_terms($taxonomy); ?>
<select id="<?php echo $taxonomy; ?>" name="<?php echo $taxonomy; ?>" class="span2">
<?php if ($terms = get_terms(array('taxonomy' => 'estados'))) : ?>
<option data-title="0" value="0">Selecione um Estado</option>
<?php foreach ($terms as $term) : ?>
<option value="<?php echo $term->term_id; ?>"><?php echo ucfirst($term->name); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
<div class="col-md-6 cidades">
<?php
$taxonomy = 'cidades'; ?>
<?php $terms = get_terms($taxonomy); ?>
<select id="<?php echo $taxonomy; ?>" name="<?php echo $taxonomy; ?>" class="span4">
<?php if ($terms = get_terms(array('taxonomy' => 'cidades'))) : ?>
<option data-title="0" value="0">Selecione uma Cidade</option>
<?php foreach ($terms as $term) : ?>
<option data-title="<?php echo $term->term_name; ?>" value="<?php echo $term->term_id; ?>"><?php echo ucfirst($term->name); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-busca">Buscar</button>
</div>
</div>
</form>
Right, but how can I relate the state to the city?
– Natanael Oliveira
When creating your taxonomy, you must declare that it has hierarchy:
register_taxonomy(
 'local', //taxonomy name
 'user', //object for which the taxonomy is created
 array( //taxonomy details
 'public' => true,
 'rewrite' => array('slug' => 'instaladores', 'with_front' => false, 'hierarchical' => true),
 'hierarchical' => true,
...
, declaring this, will appear the select for Voce to relate on the screen of creating a city , do not forget to fill the parent_item and parent_label inside the array of Labels when registering taxonomy– Luciano Victor