开发者

How do I find the largets item in an array with php (specifically, largest taxonomy_id in an array of ids)?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜