Skip to content

Instantly share code, notes, and snippets.

@alimoshen
Created February 6, 2018 11: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 alimoshen/4c36da6fd01445d7e2d355086e209768 to your computer and use it in GitHub Desktop.
Save alimoshen/4c36da6fd01445d7e2d355086e209768 to your computer and use it in GitHub Desktop.
WordPress custom function display only child terms
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;
}
$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