0

I'm starting to love this place more and more, super helpful!

Anyway, todays dilemma is as such:

I want to display as a list the child terms only, of a specific parent term, of a custom taxonomy, that apply to the current ID within the loop.

As such i want to print the children terms of the parent term 'Mens' for the taxonomy 'size' that apply to my current post id in the loop.

Hopefully my that is unambiguous enough.

Preferably i would like them returned linked to their category page. But since i couldnt crack this issue my self, im happy for anything you guys have to offer.

I know how to get all of the terms, or just a specific taxonomies terms, but not this, not at all.

Thank you

Mike

1

For actual categories:

<ul> 
<?php
    global $post;
    // grab categories of current post
    $categories = get_the_category($post->ID);
    // define arguments of following listing function
    $args = array (
        'child_of' => $categories[0], // current post's (first) category 
        'title_li' => '' // disable display of outer list item
    );
    // list child categories
    wp_list_categories($args);
?>
</ul>

The same as above with a custom taxonomy:

<ul> 
<?php
    global $post;
    // grab terms of current post, replace taxonomy name
    $terms = get_the_terms($post->ID, 'name_of_custom_taxonomy');
    // define arguments of following listing function
    $args = array (
        'child_of' => $terms[0], // current post's (first) category 
        'title_li' => '', // disable display of outer list item 
        'taxonomy' => 'name_of_custom_taxonomy' // replace as well
    );
    // list child categories
    wp_list_categories($args);
?>
</ul>

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy