0

I have a product in child category of a parent category , there are many other sibling of that child category , I want to show them separately in current product page.

Clothes (parent) > (child) Shirts Bottoms Socks

in every product of socks category I want to show shirts , bottoms and socks category separately.

1 Answer 1

1

This is how you display all child terms of a parent term:

$term_id = 8; // id of your clothes category
$taxonomy_name = 'your_taxonomy'; // e.g. 'category'
$termchildren = get_term_children( $term_id, $taxonomy_name );
if ( !empty($termchildren) ) {
            foreach ($termchildren as $termchild) {
                $term = get_term_by( 'id', $child, $taxonomy_name );
                    // Do things
            }
}

See https://developer.wordpress.org/reference/functions/get_term_children/

Not the answer you're looking for? Browse other questions tagged or ask your own question.