Created
February 6, 2018 10:55
-
-
Save alimoshen/bf2ab63435096c9cc69e37345fae650f to your computer and use it in GitHub Desktop.
WordPress custom function display only parent 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_parent_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_parent_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