1
1
10013602018-09-10 20:08:18
WordPress
1001360, 2018-09-10 20:08:18

How to make a select dropdown list with WordPress taxonomies?

There is a category taxonomy.
It has a structure
Category 1 - Sub-category 1
Category 1 - Sub-category 2
I do select like this:

<?php 
$categories = get_terms( 
    'company_category', 
    array( 'hide_empty' => false, 'parent' => 0 ) 
); ?>

<select name="catID" id="cat">
<?php
foreach ($categories as $category) {
    $catID = $category->term_id;
    $catName = $category->name;
?>
<option value="<?= $catID; ?>"><?= $catName; ?></option>
<?php } ?>
</select>

I get a drop-down list with categories of the first level
But I want to get a second drop-down list that depends on the first one
. That is, if you select Category 1 in the first drop-down list
, then in the second drop-down list you can select a Sub-category that belongs to "Category 1"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question