get_term_feed_link

Retrieves the feed link for a term.

Description

(string|false) get_term_feed_link( (int) $term_id, (string) $taxonomy = 'category', (string) $feed = '' ); 

Returns a link to the feed for all posts in a given term. A specific feed can be requested or left blank to get the default feed.

Returns (string|false)

Link to the feed for the term specified by $term_id and $taxonomy.

Parameters (3)

0. $term_id (int)
The term id.
1. $taxonomy — Optional. (string) => 'category'
Taxonomy of $term_id.. Default category.
2. $feed — Optional. (string) => ''
Feed type. Default empty.

Usage

  1. if ( !function_exists( 'get_term_feed_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // The term id. 
  5. $term_id = -1; 
  6.  
  7. // Optional. Taxonomy of `$term_id`. Default 'category'. 
  8. $taxonomy = 'category'; 
  9.  
  10. // Optional. Feed type. Default empty. 
  11. $feed = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_term_feed_link($term_id, $taxonomy, $feed); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { 
  2. $term_id = (int) $term_id; 
  3.  
  4. $term = get_term( $term_id, $taxonomy ); 
  5.  
  6. if ( empty( $term ) || is_wp_error( $term ) ) 
  7. return false; 
  8.  
  9. if ( empty( $feed ) ) 
  10. $feed = get_default_feed(); 
  11.  
  12. $permalink_structure = get_option( 'permalink_structure' ); 
  13.  
  14. if ( '' == $permalink_structure ) { 
  15. if ( 'category' == $taxonomy ) { 
  16. $link = home_url("?feed=$feed&cat=$term_id"); 
  17. elseif ( 'post_tag' == $taxonomy ) { 
  18. $link = home_url("?feed=$feed&tag=$term->slug"); 
  19. } else { 
  20. $t = get_taxonomy( $taxonomy ); 
  21. $link = home_url("?feed=$feed&$t->query_var=$term->slug"); 
  22. } else { 
  23. $link = get_term_link( $term_id, $term->taxonomy ); 
  24. if ( $feed == get_default_feed() ) 
  25. $feed_link = 'feed'; 
  26. else 
  27. $feed_link = "feed/$feed"; 
  28.  
  29. $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); 
  30.  
  31. if ( 'category' == $taxonomy ) { 
  32. /** 
  33. * Filters the category feed link. 
  34. * @since 1.5.1 
  35. * @param string $link The category feed link. 
  36. * @param string $feed Feed type. 
  37. */ 
  38. $link = apply_filters( 'category_feed_link', $link, $feed ); 
  39. } elseif ( 'post_tag' == $taxonomy ) { 
  40. /** 
  41. * Filters the post tag feed link. 
  42. * @since 2.3.0 
  43. * @param string $link The tag feed link. 
  44. * @param string $feed Feed type. 
  45. */ 
  46. $link = apply_filters( 'tag_feed_link', $link, $feed ); 
  47. } else { 
  48. /** 
  49. * Filters the feed link for a taxonomy other than 'category' or 'post_tag'. 
  50. * @since 3.0.0 
  51. * @param string $link The taxonomy feed link. 
  52. * @param string $feed Feed type. 
  53. * @param string $feed The taxonomy name. 
  54. */ 
  55. $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); 
  56.  
  57. return $link;