Using WordPress ‘get_search_comments_feed_link()’ PHP function

The get_search_comments_feed_link() WordPress PHP function retrieves the permalink for the search results comments feed.

Usage

get_search_comments_feed_link( string $search_query = '', string $feed = '' );

Parameters

  • $search_query (string) – Optional. Search query. 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_search_comments_feed_link()

Examples

This example retrieves the RSS2 comments feed link for the search term ‘technology’.

$search_query = 'technology';
$feed_type = 'rss2';
$comments_feed_link = get_search_comments_feed_link( $search_query, $feed_type );
echo $comments_feed_link; // Outputs the comments feed link for 'technology' search query

This example retrieves the Atom comments feed link for the search term ‘design’.

$search_query = 'design';
$feed_type = 'atom';
$comments_feed_link = get_search_comments_feed_link( $search_query, $feed_type );
echo $comments_feed_link; // Outputs the comments feed link for 'design' search query

This example retrieves the comments feed link for the search term ‘sports’ using the default feed type.

$search_query = 'sports';
$comments_feed_link = get_search_comments_feed_link( $search_query );
echo $comments_feed_link; // Outputs the comments feed link for 'sports' search query

This example retrieves the comments feed link for search results that include both ‘travel’ and ‘adventure’.

$search_query = 'travel+adventure';
$feed_type = 'rss2';
$comments_feed_link = get_search_comments_feed_link( $search_query, $feed_type );
echo $comments_feed_link; // Outputs the comments feed link for 'travel' and 'adventure' search query

This example displays the comments feed link for search results in a template file using the search query ‘food’.

$search_query = 'food';
$feed_type = 'atom';
$comments_feed_link = get_search_comments_feed_link( $search_query, $feed_type );
?>
<a href="<?php echo esc_url( $comments_feed_link ); ?>">Comments Feed for Food Search</a>