Grandchild Term Things Grandfather Term is It's Parent

Jack Robson asked
categories woocommerce taxonomy

I’ve got the following product categories:

Pricing Tagging

Monarch Supplies


But when I do

get_term( $labels_id ); 

It says that it’s parent is the Pricing Tagging id, not Monarch Supplies.

How can I get just the sub categories of pricing tagging excluding sub-sub-categories.


Use get_terms() and the parent argument.

‘parent’ (int|string) Parent term ID to retrieve direct-child terms of.

$parent_term_id     = 123;
$direct_child_terms = get_terms( array(
    'taxonomy' => '[taxonomy]',
    'parent'   => $parent_term_id,
) );

Don’t forget to replace [taxonomy] with whatever the taxonomy is; e.g., post_tag, product_cat, etc. Additional arguments for further customization here.

Share This
Posted in: