Advertisement
qlstudio

wp return term id from taxonomy & slug

Oct 7th, 2012
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. // get ID of the term "open" using it's slug from the taxonomy "resource_tag"
  2. $tag_open = get_term_by( 'slug', 'open', 'resource_tag' );
  3.  
  4. // get ID of the term "home" using it's slug from the taxonomy "resource_tag"
  5. $tag_home = get_term_by( 'slug', 'home', 'resource_tag' );
  6.  
  7. // add any other terms to exclude here ...
  8.  
  9. // exclude category from term list by ID ##
  10. echo ql_get_the_term_list( get_the_ID(), 'resource_tag',  '', ', ', '', array( $tag_open->term_id, $tag_home->term_id ) );
  11.  
  12. // get term list with exclusion by ID ##
  13. function ql_get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '', $exclude = array() ) {
  14.    
  15.         $exclude_string = implode ( ',', $exclude );
  16.         $terms = get_terms( $taxonomy, array(
  17.                     'exclude' => $exclude_string,
  18.                 ) );
  19.        
  20.     if ( is_wp_error( $terms ) )
  21.             return $terms;
  22.  
  23.     if ( empty( $terms ) )
  24.             return false;
  25.  
  26.     foreach ( $terms as $term ) {
  27.            
  28.             if( has_term( $term->name, $taxonomy ) ) { // filter by has_term() ##
  29.                 $link = get_term_link( $term, $taxonomy );
  30.                 if ( is_wp_error( $link ) )
  31.                     return $link;
  32.                 $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>';
  33.             }
  34.     }
  35.  
  36.     if ( $term_links ) {
  37.          
  38.             $term_links = apply_filters( "term_links-$taxonomy", $term_links );
  39.             return $before . implode( $sep, $term_links ) . $after;
  40.        
  41.         } else {
  42.            
  43.             return 'None';
  44.            
  45.         }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement