Second level subcategory

I’m trying to get anoter level subcategory to show in my select option.

I’ve managed to get one… how can i get the other?

Read More
<?php
    $taxonomies = array(CUSTOM_CAT_TYPE);
    $args = array('orderby' => 'count', 'hide_empty' => 0);

    $myterms = get_terms($taxonomies, $args);
    $output = "<select class="select" name='select_cat' title="Select Category">";
    $output .= "<option value=''>Selecteer Rubriek</option>";


    foreach ($myterms as $cate)
        {                       
        if($cate->parent == 0)
            {
            $catename = "";
            $catename = $cate->name;
            $output .='<option disabled="disabled" value="'.$cate->term_id.'">'.$catename. '</option>';
                foreach ($myterms as $subcate)
                    {
                    if($subcate->parent == $cate->term_id)
                        {                                   
                        $catename = "";
                        $catename = $subcate->name;
                        $output .='<option value="'.$subcate->term_id.'">'.'&nbsp;&nbsp;&nbsp;&nbsp;'.$catename.'</option>';
                            foreach ($subcate as $subsubcate)
                                {
                                if($subsubcate->parent == $cate->term_id)
                                    {                                   
                                    $catename = "";
                                    $catename = $subsubcate->name;
                                    $output .='<option value="'.$subsubcate->term_id.'">'.'&nbsp;&nbsp;&nbsp;&nbsp;'.$catename.'</option>';

                                    }
                                }
                        }
                    }
                }
        }


    $output .="</select>";
    echo $output;

    ?>

Any ideas?! Or perhaps a better way to get where I want to be! 🙂

Related posts

1 comment

  1. Found the solution! 🙂

    $taxonomies = array(CUSTOM_CAT_TYPE);
            foreach($taxonomies as $tax)
             {
                 $args = array(
                      'orderby'         => 'name',
                      'show_count'      => 1,
                      'pad_counts'      => 1,
                      'hierarchical'    => 1,
                      'hide_empty'      => 0,
                      'taxonomy'        => $tax,
                    );
    
                 wp_dropdown_categories( $args );
             }
    

    Thanks for helping out!

Comments are closed.