Advertisement
qlstudio

WP get_the_term_list with exclusion by ID

Oct 7th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. function ql_get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '', $exclude = array() ) {
  2.    
  3.         //$terms = get_the_terms( $id, $taxonomy );
  4.         $exclude_string = implode ( ',', $exclude );
  5.         $terms = get_terms( $taxonomy, array(
  6.                     'exclude' => $exclude_string,
  7.                 ) );
  8.        
  9.     if ( is_wp_error( $terms ) )
  10.             return $terms;
  11.  
  12.     if ( empty( $terms ) )
  13.             return false;
  14.  
  15.     foreach ( $terms as $term ) {
  16.  
  17.             //if( !in_array($term->term_id, $exclude )) { // add term to array if not excluded explicitly by ID ##
  18.                 $link = get_term_link( $term, $taxonomy );
  19.                 if ( is_wp_error( $link ) )
  20.                     return $link;
  21.                 $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
  22.             //}
  23.     }
  24.  
  25.     $term_links = apply_filters( "term_links-$taxonomy", $term_links );
  26.     return $before . join( $sep, $term_links ) . $after;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement