Using WordPress ‘get_term_feed_link()’ PHP function

The get_term_feed_link() WordPress PHP function retrieves the feed link for a term.

Usage

get_term_feed_link($term, $taxonomy = '', $feed = '')

Custom example:

// Get RSS2 feed link for a tag with ID 10
echo get_term_feed_link(10, 'post_tag', 'rss2');

Parameters

  • $term (int | WP_Term | object) – The ID or term object whose feed link will be retrieved.
  • $taxonomy (string) – Optional. Taxonomy of $term_id. Default: ”.
  • $feed (string) – Optional. Feed type. Possible values include ‘rss2’, ‘atom’. Default is the value of get_default_feed(). Default: ”.

More information

See WordPress Developer Resources: get_term_feed_link()

Examples

Retrieve the RSS2 feed link for a category with an ID of 5:

// Get RSS2 feed link for a category with ID 5
echo get_term_feed_link(5, 'category', 'rss2');

Retrieve the Atom feed link for a tag with an ID of 15:

// Get Atom feed link for a tag with ID 15
echo get_term_feed_link(15, 'post_tag', 'atom');

Retrieve the default feed link for a custom taxonomy term with an ID of 20:

// Get default feed link for a custom taxonomy term with ID 20
echo get_term_feed_link(20, 'my_custom_taxonomy');

Retrieve the RSS2 feed link for a term using a WP_Term object:

// Get term by ID
$term_object = get_term(25, 'category');

// Get RSS2 feed link for the term
echo get_term_feed_link($term_object, 'category', 'rss2');

Retrieve the default feed link for a term with an ID of 30 without specifying its taxonomy:

// Get default feed link for a term with ID 30
echo get_term_feed_link(30);