Last active
May 19, 2019 05:10
-
-
Save rhcarlosweb/b5b5dd26e401cadc7b55a32c2edcec9b to your computer and use it in GitHub Desktop.
Taxonomy Hirarchy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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