get_term_feed_link( int|WP_Term|object $term, string $taxonomy = '', string $feed = '' ): string|false
- Since
- 3.0.0
- Source
wp-includes/link-template.php:935
Description
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.
Compatibility
- WordPress
- since 3.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$termint|WP_Term|object- The ID or term object whose feed link will be retrieved.
$taxonomystringoptional- Taxonomy of
$term_id.Default:'' $feedstringoptional- Feed type. Possible values include 'rss2', 'atom'.
Default is the value of get_default_feed().Default:''
Return value
string|false- Link to the feed for the term specified by
$termand$taxonomy.
Performance profile
How much work a call to get_term_feed_link() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 13–64
- Plugin surface
- 3 hooks
- Called by
- 4
Reaches the database via get_term().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 121.
Third-party callbacks on 'category_feed_link', 'tag_feed_link', 'taxonomy_feed_link' run inside this call, and their cost is not bounded by anything here.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_term()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below get_term_feed_link() - serializeserialisation
maybe_unserialize()one call below get_term_feed_link()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_term_feed_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($term) | 13–15 | get_term() |
!empty($term) && is_wp_error() | 17–19 | get_term(), is_wp_error() |
!empty($term) && !is_wp_error() && !empty($feed) | 46–53 | get_term(), is_wp_error(), get_option(), home_url(), apply_filters() |
!empty($term) && !is_wp_error() && empty($feed) | 49–56 | get_term(), is_wp_error(), get_default_feed(), get_option(), home_url(), apply_filters() |
!empty($term) && !is_wp_error() && !empty($feed) && $taxonomy !== "category" && $taxonomy !== "post_tag" | 55–60 | get_term(), is_wp_error(), get_option(), get_taxonomy(), home_url(), apply_filters() |
!empty($term) && !is_wp_error() && !empty($feed) | 55–61 | get_term(), is_wp_error(), get_option(), get_term_link(), get_default_feed(), trailingslashit(), user_trailingslashit(), apply_filters() |
!empty($term) && !is_wp_error() && empty($feed) && $taxonomy !== "category" && $taxonomy !== "post_tag" | 58–63 | get_term(), is_wp_error(), get_default_feed(), get_option(), get_taxonomy(), home_url(), apply_filters() |
!empty($term) && !is_wp_error() && empty($feed) | 58–64 | get_term(), is_wp_error(), get_default_feed(), get_option(), get_term_link(), get_default_feed(), trailingslashit(), user_trailingslashit(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 121 instructions, 13–64 executed per call, 10 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 3
3 hooks fire while get_term_feed_link() runs, in this order:
- apply_filters( category_feed_link )filterline 983 (+48 into the body)
Filters the category feed link.
- apply_filters( taxonomy_feed_link )filterline 1004 (+69 into the body)
Filters the feed link for a taxonomy other than 'category' or 'post_tag'.
Uses · 10
- get_term()Gets all term data from database by term ID.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_default_feed()Retrieves the default feed.
- get_option()Retrieves an option value based on an option name.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- get_term_link()Generates a permalink for a taxonomy term archive.
- trailingslashit()Appends a trailing slash.
- user_trailingslashit()Retrieves a trailing-slashed string if the site is set for adding trailing slashes.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 4
- Walker_Category::start_el()Starts the element output.
- feed_links_extra()Displays the links to the extra feeds such as category feeds.
- get_category_feed_link()Retrieves the feed link for a category.
- get_tag_feed_link()Retrieves the permalink for a tag feed.
Source code
function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) { if ( ! is_object( $term ) ) { $term = (int) $term; } $term = get_term( $term, $taxonomy ); if ( empty( $term ) || is_wp_error( $term ) ) { return false; } $taxonomy = $term->taxonomy; if ( empty( $feed ) ) { $feed = get_default_feed(); } $permalink_structure = get_option( 'permalink_structure' ); if ( ! $permalink_structure ) { if ( 'category' === $taxonomy ) { $link = home_url( "?feed=$feed&cat=$term->term_id" ); } elseif ( 'post_tag' === $taxonomy ) { $link = home_url( "?feed=$feed&tag=$term->slug" ); } else { $t = get_taxonomy( $taxonomy ); $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); } } else { $link = get_term_link( $term, $term->taxonomy ); if ( get_default_feed() === $feed ) { $feed_link = 'feed'; } else { $feed_link = "feed/$feed"; } $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); } if ( 'category' === $taxonomy ) { /** * Filters the category feed link. * * @since 1.5.1 * * @param string $link The category feed link. * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */ $link = apply_filters( 'category_feed_link', $link, $feed ); } elseif ( 'post_tag' === $taxonomy ) { /** * Filters the post tag feed link. * * @since 2.3.0 * * @param string $link The tag feed link. * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */ $link = apply_filters( 'tag_feed_link', $link, $feed ); } else { /** * Filters the feed link for a taxonomy other than 'category' or 'post_tag'. * * @since 3.0.0 * * @param string $link The taxonomy feed link. * @param string $feed Feed type. Possible values include 'rss2', 'atom'. * @param string $taxonomy The taxonomy name. */ $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); } return $link;}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.