I am trying to return the hig开发者_如何学Gohest term taxonomy id of a post page or a taxonomy page.
I was sucessful at listing all taxonomy id's like this:
<?php
$terms = get_the_terms( $post->ID , 'mytaxonomy' );
if($terms) {
foreach( $terms as $term ) {
echo $term->term_taxonomy_id;
}
}
?>
This is what I am trying to do (return only the highest ID) (doesn't work):
<?php
$terms = get_the_terms( $post->ID , 'mytaxonomy' );
if($terms) {
foreach( $terms as $term ) {
echo max( '$term->term_taxonomy_id');
}
}
?>
Please help :)
NOTE: My main goal is to make this work: https://wordpress.stackexchange.com/questions/9562/multi-level-taxonomy-navigation
The max function can probably compare only two terms at a time. Keep track of the maximum term as you go through the loop - maybe:
maximum_term = max(maximum_term,term->term_taxonomy_id);
No need to use the loop at all just apply max to the $terms variable
精彩评论