get_search_feed_link

Retrieves the permalink for the search results feed.

Description

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

Returns (string)

The search results feed permalink.

Parameters (2)

0. $search_query — Optional. (string) => ''
Search query. Default empty.
1. $feed — Optional. (string) => ''
Feed type. Default empty.

Usage

  1. if ( !function_exists( 'get_search_feed_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Search query. Default empty. 
  5. $search_query = ''; 
  6.  
  7. // Optional. Feed type. Default empty. 
  8. $feed = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_search_feed_link($search_query, $feed); 
  12.  

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_search_feed_link($search_query = '', $feed = '') { 
  2. global $wp_rewrite; 
  3. $link = get_search_link($search_query); 
  4.  
  5. if ( empty($feed) ) 
  6. $feed = get_default_feed(); 
  7.  
  8. $permastruct = $wp_rewrite->get_search_permastruct(); 
  9.  
  10. if ( empty($permastruct) ) { 
  11. $link = add_query_arg('feed', $feed, $link); 
  12. } else { 
  13. $link = trailingslashit($link); 
  14. $link .= "feed/$feed/"; 
  15.  
  16. /** 
  17. * Filters the search feed link. 
  18. * @since 2.5.0 
  19. * @param string $link Search feed link. 
  20. * @param string $feed Feed type. 
  21. * @param string $type The search type. One of 'posts' or 'comments'. 
  22. */ 
  23. return apply_filters( 'search_feed_link', $link, $feed, 'posts' );