• This is probably really simple, but I’m just not seeing it.

    I have an archive page which outputs a list of posts. Under the title of each I am outputting the categories associated with this.

    <?php $location = get_the_term_list( get_the_ID(), 'location', '', ' / ',''); ?>
    <?php echo wp_strip_all_tags($location); ?>

    However, I have one category called coming-soon that I want to hide.

    I’m not sure how to amend this code to make that happen.

Viewing 1 replies (of 1 total)
  • Thread Starter jelly_bean

    (@jelly_bean)

    Found an answer:

    Exclude one category from get_the_term_list

    Add this to functions.php:

    function get_modified_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '', $exclude = array() ) {
        $terms = get_the_terms( $id, $taxonomy );
    
        if ( is_wp_error( $terms ) )
            return $terms;
    
        if ( empty( $terms ) )
            return false;
    
        foreach ( $terms as $term ) {
    
            if(!in_array($term->term_id,$exclude)) {
                $link = get_term_link( $term, $taxonomy );
                if ( is_wp_error( $link ) )
                    return $link;
                $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
            }
        }
    
        if( !isset( $term_links ) )
            return false;
    
        return $before . join( $sep, $term_links ) . $after;
    }

    My term id is 9 so use this to echo the term list without the coming soon taxonomy.

    <?php $location = get_modified_term_list( get_the_ID(), 'location', '', '/ ', '', array(9) ); ?>
    <?php echo wp_strip_all_tags($location); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Exlcude taxonomy term from output’ is closed to new replies.