Обновил
<select name="category" id="category-select">
<option value="">Выберите из списка</option>
<?php
$categories = get_terms(array(
'taxonomy' => 'category',
'hide_empty' => false,
'orderby' => 'term_order',
'order' => 'ASC',
));
function display_category_options($categories, $parent = 0, $depth = 0) {
foreach ($categories as $category) {
if ($category->parent == $parent) {
$indent = str_repeat(' ', $depth * 4);
echo '<option value="' . esc_url(get_category_link($category->term_id)) . '">' . $indent . esc_html($category->name) . '</option>';
display_category_options($categories, $category->term_id, $depth + 1);
}
}
}
display_category_options($categories);
?>
</select>
<script>
document.getElementById('category-select').addEventListener('change', function() {
const selectedValue = this.value;
if (selectedValue) {
window.location.href = selectedValue;
}
});
</script>