get_post_comments_feed_link( int $post_id = 0, string $feed = '' ): string
- Since
- 2.2.0
- Source
wp-includes/link-template.php:745
Compatibility
- WordPress
- since 2.2.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
$post_idintoptional- Post ID. Default is the ID of the global
$post.Default:0 $feedstringoptional- Feed type. Possible values include 'rss2', 'atom'.
Default is the value of get_default_feed().Default:''
Return value
string- The permalink for the comments feed for the given post on success, empty string on failure.
Performance profile
How much work a call to get_post_comments_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
- 16–71
- Plugin surface
- 1 hook
- Called by
- 5
Reaches the database via get_post().
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 129.
Third-party callbacks on 'post_comments_feed_link' run inside this call, and their cost is not bounded by anything here.
5 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()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_post_comments_feed_link() - serializeserialisation
maybe_unserialize()one call below get_post_comments_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 · 32 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_post_comments_feed_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($feed) && !($post instanceof) | 16 | absint(), get_post() |
empty($feed) && !($post instanceof) | 19 | absint(), get_default_feed(), get_post() |
!empty($feed) && !($post instanceof) | 19 | absint(), get_the_ID(), get_post() |
empty($feed) && !($post instanceof) | 22 | absint(), get_the_ID(), get_default_feed(), get_post() |
!empty($feed) && $post instanceof && !get_option() | 40–46 | absint(), get_post(), get_option(), home_url(), feed(), apply_filters() |
empty($feed) && $post instanceof && !get_option() | 43–49 | absint(), get_default_feed(), get_post(), get_option(), home_url(), feed(), apply_filters() |
!empty($feed) && $post instanceof && !get_option() | 43–49 | absint(), get_the_ID(), get_post(), get_option(), home_url(), feed(), apply_filters() |
empty($feed) && $post instanceof && !get_option() | 46–52 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), home_url(), feed(), apply_filters() |
!empty($feed) && $post instanceof && get_option() | 53–58 | absint(), get_post(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
!empty($feed) && $post instanceof && get_option() | 53–58 | absint(), get_post(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
empty($feed) && $post instanceof && get_option() | 56–61 | absint(), get_default_feed(), get_post(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
empty($feed) && $post instanceof && get_option() | 56–61 | absint(), get_default_feed(), get_post(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
20 further outcomes, up to 71 instructions
!empty($feed) && $post instanceof && get_option() | 56–61 | absint(), get_the_ID(), get_post(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
!empty($feed) && $post instanceof && get_option() | 56–61 | absint(), get_the_ID(), get_post(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id !== false | 59–64 | absint(), get_post(), get_option(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id !== false | 59–64 | absint(), get_post(), get_option(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
empty($feed) && $post instanceof && get_option() | 59–64 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
empty($feed) && $post instanceof && get_option() | 59–64 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id === false | 60–65 | absint(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id === false | 60–65 | absint(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id !== false | 62–67 | absint(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id !== false | 62–67 | absint(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id !== false | 62–67 | absint(), get_the_ID(), get_post(), get_option(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id !== false | 62–67 | absint(), get_the_ID(), get_post(), get_option(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id === false | 63–68 | absint(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id === false | 63–68 | absint(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id === false | 63–68 | absint(), get_the_ID(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
!empty($feed) && $post instanceof && get_option() && $post_id === false | 63–68 | absint(), get_the_ID(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id !== false | 65–70 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), get_permalink(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id !== false | 65–70 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), get_permalink(), home_url(), get_default_feed(), add_query_arg(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id === false | 66–71 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), trailingslashit(), get_default_feed(), user_trailingslashit(), apply_filters() |
empty($feed) && $post instanceof && get_option() && $post_id === false | 66–71 | absint(), get_the_ID(), get_default_feed(), get_post(), get_option(), get_option(), get_option(), _get_page_link(), home_url(), get_default_feed(), add_query_arg(), 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: 129 instructions, 16–71 executed per call, 12 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 · 1
One hook fires while get_post_comments_feed_link() runs, in this order:
- apply_filters( post_comments_feed_link )filterline 820 (+75 into the body)
Filters the post comments feed permalink.
Uses · 12
- absint()Converts a value to non-negative integer.
- get_the_ID()Retrieves the ID of the current item in the WordPress Loop.
- get_default_feed()Retrieves the default feed.
- get_post()Retrieves post data given a post ID or post object.
- get_option()Retrieves an option value based on an option name.
- _get_page_link()Retrieves the page permalink.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- add_query_arg()Retrieves a modified URL query string.
- 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 · 5
- comments_rss()Return link to the post RSS feed.
- feed_links_extra()Displays the links to the extra feeds such as category feeds.
- post_comments_feed_link()Displays the comment feed link for a post.
- redirect_canonical()Redirects incoming links to the proper URL based on the site url.
- redirect_guess_404_permalink()Attempts to guess the correct URL for a 404 request based on query vars.
Source code
function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { $post_id = absint( $post_id ); if ( ! $post_id ) { $post_id = get_the_ID(); } if ( empty( $feed ) ) { $feed = get_default_feed(); } $post = get_post( $post_id ); // Bail out if the post does not exist. if ( ! $post instanceof WP_Post ) { return ''; } $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; if ( get_option( 'permalink_structure' ) ) { if ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post_id ) { $url = _get_page_link( $post_id ); } else { $url = get_permalink( $post_id ); } if ( $unattached ) { $url = home_url( '/feed/' ); if ( get_default_feed() !== $feed ) { $url .= "$feed/"; } $url = add_query_arg( 'attachment_id', $post_id, $url ); } else { $url = trailingslashit( $url ) . 'feed'; if ( get_default_feed() !== $feed ) { $url .= "/$feed"; } $url = user_trailingslashit( $url, 'single_feed' ); } } else { if ( $unattached ) { $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id, ), home_url( '/' ) ); } elseif ( 'page' === $post->post_type ) { $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id, ), home_url( '/' ) ); } else { $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id, ), home_url( '/' ) ); } } /** * Filters the post comments feed permalink. * * @since 1.5.1 * * @param string $url Post comments feed permalink. */ return apply_filters( 'post_comments_feed_link', $url );}Changelog
Introduced in 2.2.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 6.7.7 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.