Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
echo '<span>Familles<br>';
$terms_id = _get_term_hierarchy( 'animal' );
$post_terms = get_the_terms( $post->ID, 'animal' );
$terms_id = array_intersect_key( $terms_id, $post_terms );
foreach ( $terms_id as $parent => $enfants ) {
$term_links = rtrim( $term_links, ', ' );
if ( ! empty( $term_links) ){
$term_links .= '<br />';
}
$term = get_term( $parent, 'animal' );
$link = get_term_link( $term, 'animal' );
if ( is_wp_error( $link ) )
continue;
$term_links .= '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a> : ';
foreach ($enfants as $i => $id) {
$term = get_term( $id, 'animal' );
$link = get_term_link( $term, 'animal' );
if ( is_wp_error( $link ) )
continue;
$term_links .= '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>, ';
}
}
echo rtrim( $term_links, ', ' );
echo '</span><br>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment