Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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