Skip to content

Instantly share code, notes, and snippets.

@JulioPotier
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulioPotier/8a3bf51e913e5d7d17f7 to your computer and use it in GitHub Desktop.
Save JulioPotier/8a3bf51e913e5d7d17f7 to your computer and use it in GitHub Desktop.
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