WordPress.org

Forums

Display Child Taxonomy on Posts without Parent (1 post)

  1. ddxv
    Member
    Posted 1 year ago #

    Hello! I'd love some help with this. =)

    I'd love to remove the parent terms of a custom taxonomy from displaying on posts.

    Currently it displays, Parent, Parent 2, Child but I would only like to display the Child.

    What is the correct php for doing so?

    I found this code, but I don't know how to modify it to only show the final child.

    <?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>' . __('Categories:','om_theme') . '</b> ' . join( ", ", $output ) . '</p>';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic