get_post_type_archive_feed_link

Retrieves the permalink for a post type archive feed.

Description

(string|false) get_post_type_archive_feed_link( (string) $post_type, (string) $feed = '' ); 

Returns (string|false)

The post type feed permalink.

Parameters (2)

0. $post_type (string)
The post type.
1. $feed — Optional. (string) => ''
Feed type. Default empty.

Usage

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

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_post_type_archive_feed_link( $post_type, $feed = '' ) { 
  2. $default_feed = get_default_feed(); 
  3. if ( empty( $feed ) ) 
  4. $feed = $default_feed; 
  5.  
  6. if ( ! $link = get_post_type_archive_link( $post_type ) ) 
  7. return false; 
  8.  
  9. $post_type_obj = get_post_type_object( $post_type ); 
  10. if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { 
  11. $link = trailingslashit( $link ); 
  12. $link .= 'feed/'; 
  13. if ( $feed != $default_feed ) 
  14. $link .= "$feed/"; 
  15. } else { 
  16. $link = add_query_arg( 'feed', $feed, $link ); 
  17.  
  18. /** 
  19. * Filters the post type archive feed link. 
  20. * @since 3.1.0 
  21. * @param string $link The post type archive feed link. 
  22. * @param string $feed Feed type. 
  23. */ 
  24. return apply_filters( 'post_type_archive_feed_link', $link, $feed );