<?php
$args = array(
\'taxonomy\' => \'category\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hierarchical\' => true,
\'hide_empty\' => false,
);
$the_query = new WP_Term_Query($args);
$categories = $the_query->get_terms();
foreach($categories as $cat){
$ancestors = get_ancestors( $cat->term_id, \'category\' );
$cat->ancestors = $ancestors; // array( 0 => 15, 1 => 45 ) - 3rd level term
$cat->depth = count( $ancestors ) ;
}
?>
<select>
<?php
foreach($categories as $cat){
echo \'<option value="\'.$cat->term_id.\'">\'.str_repeat(\' \',$cat->depth).$cat->name.\'</option>\';
}
?>
</select>