Skip to content

Instantly share code, notes, and snippets.

@tiltos
Created March 15, 2012 06:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiltos/2042540 to your computer and use it in GitHub Desktop.
Save tiltos/2042540 to your computer and use it in GitHub Desktop.
WP: Get custom taxonomy parent
<?php
$term = get_the_terms( $post->ID, 'custom-taxonomy' );
foreach ($term as $key) {
$parents = get_ancestors( $key->term_id, 'custom-taxonomy' );
foreach ($parents as $parent) {
$key = get_term($parent, 'custom-taxonomy');
$parent = $key->slug;
}
}
echo $parent;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment