I know that i can use get_term_children() function to get childs for some parent for some taxonomy. For example, the taxonomy can be a product category.
For example, to display children product categories for a parent product category with ID = 70 i can use:
$taxonomyName = "product_cat";
$termID = "70";
$termchildren = get_term_children( $termID, $taxonomyName );
var_dump($termchildren);
echo '<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo '<li><a href="' . get_term_link( $term->term_id, $term->taxonomy ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
I tried, the code is working. But what is the id of "THE VERY-VERY TOP / BASE / 0-level" product category in wp? I want to show only first-level it’s parents. I tried "0" and "-1" as $termID, but no luck – it shows nothing. What is the right value?
2
Answers
Try this:
References:
get_categories
get_terms
so close but need to check parent: