• Resolved Jan

    (@locke85)


    Hi there,

    I need to use a custom RSS feed for this podcast that excludes certain episodes from the feed (based on tag). This threat from shanDB was somewhat helpful, but did solve the issue.

    (1) I added the following to the function.php:

    // Podcast - Exclude episodes w tag sneak-preview from RSS feed
    
    // Register the custom feed
    
    function podcast_no_sneak_preview_feed() {
    
    add_feed('podcast_no_sneak_preview', 'customRSSFunc');
    
    }
    
    add_action('init', 'podcast_no_sneak_preview_feed');
    
    // Function to render the custom feed content
    
    function customRSSFunc() {
    
    // Load the custom RSS feed template
    
    get_template_part('rss', 'podcast_no_sneak_preview');
    
    }
    
    // Modify the custom feed query
    
    function exclude_sneak_preview_posts_from_custom_feed($query) {
    
    // Check if the query is for the custom feed
    
    if ( $query->is_feed() && $query->get('feed') === 'podcast_no_sneak_preview' ) {
    
    // Get the tag ID for the 'sneak-preview' tag
    
    $tag_id = 96; // Replace 96 with the actual tag ID of "sneak-preview" tag
    
    // Exclude posts with the 'sneak-preview' tag from the custom feed
    
    $query->set('tag__not_in', array($tag_id));
    
    }
    
    }
    
    add_action('pre_get_posts', 'exclude_sneak_preview_posts_from_custom_feed');
    
    // Callback function to connect custom feed with the RSS template file
    
    function custom_feed_template($templates) {
    
    if (get_query_var('feed') === 'podcast_no_sneak_preview') {
    
    $templates = array('rss-podcast_no_sneak_preview.php');
    
    }
    
    return $templates;
    
    }
    
    add_filter('feed_template', 'custom_feed_template');

    (2) then created a copy of the feed-podcast.php, renamed the file to “rss-name.php” and saved the file to the root directory of the child theme.

    (3) then I cleared the cache and reset the display rule

    (4) when calling the custom feed URL this error message appears.

    Please let me know what I’m missing.

    Thanks,

    Jan

    • This topic was modified 1 year, 8 months ago by Jan.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Serhiy Zakharchenko

    (@zahardoc)

    Hi Jan!

    Please remove all your previous changes and put the following code in your functions.php file ( replace excluded_tag_slug with your tag slug ):

    add_filter('ssp_episode_query_args', function($args){
    	$args['tax_query'][] = array(
    		'taxonomy' => 'post_tag',
    		'field'    => 'slug',
    		'terms'    => array( 'excluded_tag_slug' ),
    		'operator' => 'NOT IN',
    	);
    
    	return $args;
    });

    Please let me know if that worked for you.

    Best regards,
    Sergiy.

    Thread Starter Jan

    (@locke85)

    Hi Sergiy,

    this worked very well.

    Thanks for your great support.

    Best regards,

    Jan

    Plugin Author Serhiy Zakharchenko

    (@zahardoc)

    Hi Jan,

    Great, I’m glad to hear that it worked for you!

    If you enjoy using our plugin and have a moment to spare, we would greatly appreciate your support in helping it grow by providing 5-star feedback here.

    Thank you and best regards,
    Sergiy.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom RSS Feed’ is closed to new replies.