Skip to content

Instantly share code, notes, and snippets.

@rhcarlosweb
Last active May 19, 2019 05:10
Show Gist options
  • Save rhcarlosweb/b5b5dd26e401cadc7b55a32c2edcec9b to your computer and use it in GitHub Desktop.
Save rhcarlosweb/b5b5dd26e401cadc7b55a32c2edcec9b to your computer and use it in GitHub Desktop.
Taxonomy Hirarchy
<?php
function taxonomy_hierarchy( $taxonomy ) {
global $post;
$terms = get_the_terms( $post->ID, $taxonomy );
foreach ( $terms as $term ) {
if ( $term->parent == 0 ) {
$myparent = $term;
}
}
echo '' . $myparent->name . '';
foreach ( $terms as $term ) {
if ( $term->parent != 0 ) {
$child_term = $term;
echo '' . $child_term->name . '';
}
}
}
add_filter( 'the_category_list', 'ci_theme_the_category_list_remove_parent_categories', 10 );
function ci_theme_the_category_list_remove_parent_categories( $categories ) {
$categories_tmp = $categories;
foreach ( $categories_tmp as $child_cat ) {
foreach ( $categories_tmp as $key => $parent_cat ) {
if ( isset( $categories[ $key ] ) ) {
if ( cat_is_ancestor_of( $parent_cat, $child_cat ) ) {
unset( $categories[ $key ] );
}
}
}
}
return $categories;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment