• Help needed.

    Having created a custom taxonomy named MOVIE with sub-taxonomy terms as ACTOR, DIRECTOR, PRODUCER, etc. now I’m willing to list into the post’s content its related custom taxonomies’ children.

    Example:

    Post Title: MI4 GHOST PROTOCOL

    Actors: Tom Cruise, Jeremy Renner, Léa Seydoux, Josh Holloway, Michael Nyqvist,Simon Pegg, Ving Rhames, Paula Patton, Anil Kapoor, Vladimir Mashkov, Samuli Edelmann, Ilia Volokh, Miraj Grbic, Ivan Shvedoff, Pavel Kríz, April Stewart

    … etc…

    Looked in and tested lots of codes but none satisfy my need.

    Here are some of the codes I looked at:

    This one pulls out all the post’s taxonomies in a nice way (but I need only the actors child terms of the MI4 post):

    <?php the_taxonomies('before=<ul>&after=</ul>'); ?>

    This one pulls out an unordered list of actors, directors and producers (all the child terms of MOVIES):

    <?php $actor =""; foreach((get_the_terms( $post->ID, 'movies' )) as $actorcat) {if ($actorcat->parent |= 0) {$actor .= $actorcat->name;}} echo $actor ?>

    This one gives the same result as above, but with ul style:

    <?php
    $taxonomy = 'movies';
    $terms = get_the_terms( $post->ID , $taxonomy );
    
    if ( !empty( $terms ) ) :
    
    echo '<ul>';
    
    foreach ( $terms as $term ) {
    	$link = get_term_link( $term, $taxonomy );
    	if ( !is_wp_error( $link ) )
    		echo '<li class="' . $term->slug. '"><a href="' . $link . '" rel="tag">' . $term->name . '</a></li>';
    }
    
    echo '</ul>';
    
    endif;
    ?>

    This one pulls out all the entire list of actors (I need the actors of the movie post MI4):

    <?php
    $termID = 312;
    $taxonomyName = "movies";
    $termchildren = get_term_children(  $termID, $taxonomyName );
    
    echo '<ul>';
    foreach ($termchildren as $child) {
    	$term = get_term_by( 'id', $child, $taxonomyName );
    	echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
    }
    echo '</ul>';
    ?>

    and so on.

    Can someone please give a suggestion?

  • The topic ‘Custom Taxonomies Children's Listing’ is closed to new replies.