0

The title is self-explanatory, but let me say a word on this...

I want to get the terms of a specific parent, but also include the parent itself in the returned terms. I tried something this $args['parent'] = $args['include'] = $tax->term_id; but unfortunately it didn't work...

I'm thinking to find the parent of the parent, and do something like this $args['parent'] = {id of grandfather}; $args['exclude_treeint'] = array({ids of siblings of the parent});

But isn't this an overkill of a solution? Am I missing something obvious here? TIA

1 Answer 1

2

I don't think there's a way you can setup the arguments such that you can get all children of a term and that term in one call, so you'll probably just have to tack on the parent as a separate call.

Using get_terms for the children, then get_term.

$parent_id = 100; // set as appropriate
$terms = get_terms( array(
    'taxonomy' => 'YOURTAX',
    'hide_empty' => false, // omit if not applicable (used for testing)
    'child_of' => $parent_id,
) );

$terms[] = get_term( $parent_id, 'YOURTAX' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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