I am currently using this code to display the final child in a hierarchical taxonomy. For example, a post tagged 20th Century > 1990s > 1994 should ultimately only show 1994.
The code below works for most Parent/Child groups except for ones that end with 0s and have a child of 0. For example, 20th Century > 1990s > 1990 outputs 1990s (and not 1990).
I think the problem is that array() is using an alphanumerical method that outputs 20xxxx, 1990, 1990x. Thus thinking the final child is 1990s (not 1990).
Is there a way to ignore letters in an array? Or is there a better order to use than array()?
<?php
$terms = get_the_terms( $post->ID, 'From' );
if ( !empty( $terms ) ) {
$output = array();
foreach ( $terms as $term ){
if( 0 != $term->parent )
$output[] = '<a href="' . get_term_link( $term ) .'">' . $term->name . '</a>';
}
if( count( $output ) )
echo '<p><b>' . __('','From') . '</b> ' . end($output) . '</p>';
}
?>
If you need, you can also preview my site here: dev.jamesoclaire.com The first post shows "2010s" when instead it should show "2010"