$args = array(
\'post_type\' => \'listing\',
\'order\' => \'ASC\',
\'hide_empty\' => false,
\'parent\' => 0,
);
$listCatTerms = get_terms( \'listing-category\',$args);
if ( ! empty( $listCatTerms ) && ! is_wp_error( $listCatTerms ) ){
echo "<ul>";
foreach($listCatTerms as $listCatTerm) {
//parent categories
echo \'<li>\'.$listCatTerm->name.\'</li>\';
//get childern term ID
$term_children = get_term_children( $listCatTerm->term_id, \'listing-category\' );
foreach ( $term_children as $child ) {
//Get all Term data from database by Term field and data.
$term = get_term_by( \'id\', $child, \'listing-category\' );
//childern categories of its parent category
echo \'<li class="lp-wrap-cats">\'.$term->name.\'</li>\';
}
}
echo "</ul>";
}