Return to Snippet

Revision: 50350
at August 18, 2011 13:37 by noelj


Initial Code
function get_term_parents( $id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
    $chain = '';
    $parent = &get_term( $id, $taxonomy );
    if ( is_wp_error( $parent ) )
            return $parent;

    if ( $nicename )
            $name = $parent->slug;
    else
            $name = $parent->name;

    if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
            $visited[] = $parent->parent;
            $chain .= get_term_parents( $parent->parent, $link, $separator, $nicename, $visited );
    }

    if ( $link )
            $chain .= '<a href="' . get_term_link( $parent->slug, $taxonomy ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
    else
            $chain .= $name.$separator;

    return $chain;
}

Initial URL

                                

Initial Description

                                

Initial Title
Wordpress Get Custom Taxonomy/Term Parents - get_term_parents()

Initial Tags
php, wordpress

Initial Language
PHP