WordPress.org

Ready to get started?Download WordPress

Forums

Exclude Term from get the term list not working when excluding all post terms (3 posts)

  1. bazel
    Member
    Posted 2 years ago #

    In this post @keesiemeijer gives a solution for excluding term from get the term list. This is throwing error
    Warning: join() [function.join]: Invalid arguments passed
    when all the terms from the post are excluded

    This is the function

    function my_get_the_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>';
    		}
    	}
    
    	$term_links = apply_filters( "term_links-$taxonomy", $term_links );
    
    	return $before . join( $sep, $term_links ) . $after;
    }

    and this is the code to exclude terms

    <?php echo my_get_the_term_list( $post->ID, '$taxonomy', '', ' ', '', array($term_id) ); ?>

    Thanks

  2. p0mP
    Member
    Posted 2 years ago #

    I have the same problem...
    @keesiemeijer can you please help me out or maybe PM you ?

  3. qstudio
    Member
    Posted 1 year ago #

    The trick is to use the exclude parameter with get_terms before returning the list.

    http://pastebin.com/FjXm9C3u

Topic Closed

This topic has been closed to new replies.

About this Topic