Posted By

selfmadepsyche on 02/17/09


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

maxvee8


Exclude Categories from RSS Feed


 / Published in: PHP
 

URL: http://www.smashingmagazine.com/2008/12/02/10-useful-rss-hacks-for-wordpress/

Get the numeric ID of the category you want to exclude and edit the functions.php file in your theme. Code explanation. This hack works exactly the same way as the previous one: create a custom function to exclude the category that you don’t want to appear in your RSS feed, and then use the super-useful addfilter() function to apply it to the preget_posts() WordPress core function.

  1. function myFilter($query) {
  2. if ($query->is_feed) {
  3. $query->set('cat','-5'); //Don't forget to change the category ID =^o^=
  4. }
  5. return $query;
  6. }
  7.  
  8. add_filter('pre_get_posts','myFilter');

Report this snippet  

You need to login to post a comment.