Created
February 6, 2018 11:03
-
-
Save alimoshen/4c36da6fd01445d7e2d355086e209768 to your computer and use it in GitHub Desktop.
WordPress custom function display only child terms
This file contains hidden or 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
function get_child_terms_function($postid=null,$taxonomy){ | |
if ($postid === null) | |
return false; | |
$terms=wp_get_post_terms($postid,$taxonomy); | |
if($terms){ | |
foreach ( $terms as $term ) { | |
if($term->parent!='0') $termarr[]=$term; | |
} | |
return $termarr; | |
} | |
return false; | |
} |
This file contains hidden or 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
$terms = get_child_terms_function( $post_id, 'your_custom_taxonomy' ); | |
foreach ( $terms as $term ) { | |
echo($term->name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment