qlstudio

WP get_the_term_list with exclusion by ID

Oct 7th, 2012
176
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×