That's what the get_term
function is for:
$term_id = 21; // Lucky number :)
$child_term = get_term( $term_id, 'category' );
$parent_term = get_term( $child_term->parent, 'category' );
Replace 'category'
with whatever taxonomy you're using.
Вопрос
In page I have ID of term child, I need find out this child parent by child ID, it's passible, maybe someone can help with this ?
Решение
That's what the get_term
function is for:
$term_id = 21; // Lucky number :)
$child_term = get_term( $term_id, 'category' );
$parent_term = get_term( $child_term->parent, 'category' );
Replace 'category'
with whatever taxonomy you're using.
Другие советы
$terms = get_the_terms( $_product->id , 'product_cat');
if($terms) {
foreach( $terms as $term ) {
$term = get_term_by("id", $term->parent, "product_cat");
if ($term->parent > 0) {
$term = get_term_by("id", $term->parent, "product_cat");
}
$cat_obj = get_term($term->term_id, 'product_cat');
$cat_name = $cat_obj->name;
}
}
echo '<br />('. $cat_name . ')';