WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to modify a specific RSS feed, without affecting others? (2 posts)

  1. Jason
    Member
    Posted 2 years ago #

    Hi all

    I have a site with 2 separate feeds - one for the main blog, and the other for a custom post type:

    Blog Posts feed - [WEBSITE URL]/feed
    CPT feed - [WEBSITE URL]/feed/?post_type=podcasts

    In order for the podcasts feed to validate in iTunes, I append a direct link to the MP3 file using the following code:

    function mtg_podcast_include($content) {// Including the podcast link in the podcast RSS feed
    	global $wp_query;
    	$postid = $wp_query->post->ID;
    	$mtg_podcast_url = get_field('mtg_podcast_file_url');
    	if(is_feed()) {
    		if($mtg_podcast_url !== '') {
    			$content = $content.'<a href="'.$mtg_podcast_url.'" rel="enclosure">Download MP3</a>';
    		} else {
    			$content = $content;
    		}
    	}
    	return $content;
    }
    add_filter('the_excerpt_rss', 'mtg_podcast_include');
    add_filter('the_content', 'mtg_podcast_include');

    The problem is, a download link is also appearing at the end of each post in the blog posts feed. Can anyone tell me how I go about modifying only the podcasts feed?

    Any help is appreciated!

  2. Jason
    Member
    Posted 2 years ago #

    Figured it out - by adding a check for the post type, I was able to limit my edits to only show up in the custom post type's RSS feed:

    Changed this - if(is_feed()) {

    to this - if(is_feed() && get_post_type() == 'podcasts') {

Topic Closed

This topic has been closed to new replies.

About this Topic