The get_post_type_archive_feed_link() WordPress PHP function retrieves the permalink for a post type archive feed.
Usage
get_post_type_archive_feed_link( $post_type, $feed = '' );
Custom Example:
echo get_post_type_archive_feed_link( 'product', 'atom' );
Output:
https://example.com/feed/?post_type=product&feed=atom
Parameters
$post_type (string)
: The post type for which you want to retrieve the archive feed link.$feed (string)
: (Optional) The feed type. Possible values include ‘rss2’, ‘atom’. Default is the value ofget_default_feed()
.
More information
See WordPress Developer Resources: get_post_type_archive_feed_link()
Examples
Get the RSS2 feed link for a custom post type
This code retrieves the RSS2 feed link for a custom post type called ‘events’.
echo get_post_type_archive_feed_link( 'events' );
Get the Atom feed link for a custom post type
This code retrieves the Atom feed link for a custom post type called ‘podcasts’.
echo get_post_type_archive_feed_link( 'podcasts', 'atom' );
Display the feed link for a custom post type in an HTML anchor tag
This code displays the RSS2 feed link for a custom post type called ‘news’ in an anchor tag.
echo '<a href="' . get_post_type_archive_feed_link( 'news' ) . '">Subscribe to our news feed</a>';
Get the default feed link for a custom post type and override the feed type
This code retrieves the default feed link for a custom post type called ‘recipes’ and sets the feed type to ‘atom’ using a filter.
add_filter( 'default_feed', function() { return 'atom'; } ); echo get_post_type_archive_feed_link( 'recipes' );
Get the feed link for a built-in post type
This code retrieves the RSS2 feed link for the built-in ‘post’ post type.
echo get_post_type_archive_feed_link( 'post' );