how to add filter in custom rss feed

I have this code for my 2 custom rss feed, I wanted to put filter on custom_rss2 only. Like filter the feed by category 7 and limit post by 5. But my filter affecting all the rss feed. thanks in advance.

add_action( ‘init’, ‘custom_feeds’ );
function custom_feeds()
{
foreach( array( ‘custom_rss1’, ‘custom_rss2’ ) as $name )
{
add_feed( $name,
function() use ( $name )
{
get_template_part( ‘rss’, $name );
}
);
}
}

function feedFilter($query) {
if ($query->is_feed) {
$query->set(‘cat’, ‘7’);
$query->set(‘posts_per_page’,’5′);
}
return $query;
}
add_filter(‘pre_get_posts’,’feedFilter’);

Read more here:: how to add filter in custom rss feed

Leave a Reply

Your email address will not be published. Required fields are marked *