{"id":77591,"date":"2012-05-08T11:00:20","date_gmt":"2012-05-08T15:00:20","guid":{"rendered":"http:\/\/wpmu.org\/?p=77591"},"modified":"2012-05-08T12:08:40","modified_gmt":"2012-05-08T16:08:40","slug":"how-to-exclude-a-category-from-your-wordpress-feed","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-exclude-a-category-from-your-wordpress-feed\/","title":{"rendered":"How to Exclude a Category from Your WordPress Feed"},"content":{"rendered":"<p>If you\u2019ve ever wanted to keep a certain category out of your RSS feed, there\u2019s an easy way to do that. Just place the following code in your Functions file. (Appearance &gt; Editor &gt; Theme Functions \u2013 functions.php)<\/p>\n<p>Simply insert the ID number from the category that you want to exclude in the spot where you see the &#8220;1&#8221; in the example below. (Note: include the minus sign &#8212; e.g. -2, -5, etc.)<\/p>\n<p>If you aren\u2019t sure how to find the ID for your categories, you can take a look at <a href=\"https:\/\/wpmudev.com\/blog\/how-to-find-the-ids-of-wordpress-categories-posts-pages-and-more\/\" target=\"_blank\">this post<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<pre>function excludecatfeed($query) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if(is_feed()) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $query-&gt;set('cat','-1');\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return $query;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n}\r\nadd_filter('pre_get_posts', 'excludecatfeed');<\/pre>\n<p>&nbsp;<\/p>\n<p>If you would like to exclude more than one category, then just include the other ID numbers beside the first like so:<\/p>\n<pre>$query-&gt;set('cat','-1, -5, -7');<\/pre>\n<h2><strong>The Code in Action<\/strong><\/h2>\n<p>And here\u2019s the function in action. You can see that the three posts from the my \u201cVideo\u201d category have all disappeared after I excluded that category.<\/p>\n<p><a rel=\"lightbox[77591]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-exclude-a-category-from-your-wordpress-feed\/excluded-2\/\" rel=\"attachment wp-att-77596\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77596\" title=\"excluded\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/excluded1.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"632\" height=\"674\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This trick lets you decide which categories to publish via RSS.<\/p>\n","protected":false},"author":84404,"featured_media":205595,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[152,803],"tutorials_categories":[],"class_list":["post-77591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-categories","tag-rss"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/77591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=77591"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/77591\/revisions"}],"predecessor-version":[{"id":205596,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/77591\/revisions\/205596"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/205595"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=77591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=77591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=77591"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=77591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}