我已经更新了我的PHP代码。我设法将所有父母分类法及其子项放在不同的选择框中。我想要帮助以下内容:当我改变父母时,我希望第二个选择仅显示他的孩子。
function categories_header_form()
{
?>
<div id="header-form">
<h3 class="form-title">
<?php echo 'Αναζήτηση προϊόντων ανά περιοχή' ?>
</h3>
<form id="search-form" action="#" method="post" >
<div class="form-container">
<?php nomoi(); ?>
<?php towns(); ?>
<?php products_selection(); ?>
<button type="submit" class="button" id="search-form-button">Εύρεση</button>
</div>
</form>
</div>
<?php
}
function products_selection()
{
$args = array(
'post_type' => 'seller',
'taxonomy' => 'category',
'hide_empty' => 0,
'exclude' => 1,1078,1079
);
$products = get_categories( $args );
if ( $products ) {
echo '<select id="products-select">';
echo '<option selected="" disabled="" value="0"><span>Προϊόντα</span></option>';
foreach ($products as $product) {
echo '<option class="product-name" id="'. $product->term_id .'">'. $product->name .'</option>';
}
echo '</select>';
}
}
function nomoi()
{
$args = array(
'post_type' => 'seller',
'taxonomy' => 'nomos',
'hide_empty'=> 0,
'parent' => 0
);
$categories = get_categories( $args );
if ( $categories ) {
// print_r($categories);
echo '<select id="nomoi-select">';
echo '<option selected="" disabled="" value="0"><span>Νομοί</span></option>';
foreach ($categories as $category) {
$id = $category->term_id;
$name = $category->name;
$taxonomy = $category->taxonomy;
echo '<option class="nomos" id="'. $id .'">'. $name .'</option>';
}
echo '</select>';
}
}
function towns()
{
$args = array(
'taxonomy' => 'nomos',
'hide_empty' => 0,
'hierarchical' => true,
'depth' => 1,
);
$cats = get_categories( $args );
echo '<select id="town-select">';
echo '<option selected="" disabled="" value="0"><span>Πόλεις</span></option>';
foreach ($cats as $cat) {
$cat_name = $cat->name;
$id = $cat->cat_ID;
echo '<option class="town" id="'. $id .'">'. $cat_name .'</option>';
}
echo '</select>';
}