Home > Programming > Limit RSS to certain categories in Wordpress.

Limit RSS to certain categories in Wordpress.

December 19th, 2009 Jimmy Leave a comment Go to comments

If you’re like me, you may once in a while have something to write about that isn’t necessarily related to your overall blog topic. Take me for example. My blog is mainly about internet and application development (programming) however sometimes I find a really cool tip or trick that isn’t necessarily related, such as a howto for example. Using this code I can exclude those posts from my RSS feeds. That way my main RSS subscribers don’t get caught reading off-topic posts, but they are there if they want to read them on the site. I then include just the headlines of those posts on my extended recent posts sidebar widget.

Anyways enough of the blabbing on onto the code. This code excludes categories 35 and 45 from my RSS feeds. You can get the category ID’s on your category admin page in your Wordpress dashboard.

add_filter('pre_get_posts', 'filterRSSQuery');
function filterRSSQuery($query) {
    if ( $query->is_feed ) {
        $query->set('cat', '-30,-45');
    }   

    return $query;
}
Categories: Programming Tags: , ,
Digg: DIGG ME
  1. No comments yet.
  1. No trackbacks yet.