Help with a get_categories () drop down menu - I want it to show in heirachial form
-
31-10-2019 - |
Question
I have a drop down menu that displays all of the terms for one of my custom taxonomies using get_categories (). It displays fine in alphabetical form. However, what i want to know is how can i have the terms listed in a hierarchial form in a drop down menu, so they appear like this -
Parent Category 1
- Child One
- Child Two
Parent Category 2
- Child One
Here is my code for the drop down menu:
</select>
<span>By Category: </span>
<select name="category">
<option name="all" value="">All Categories</option>
<?php $categories_filter = get_categories( 'taxonomy=tshirt_categories' );
foreach( $categories_filter as $category_option ) {
echo '<option name=' . $category_option->slug . ' value="' . $category_option->slug . '" /> ' . $category_option->name . '</option>' . "\n";
}
?>
</select>
Once again thanks for any advice you guys may have!
Mike
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange