Excluding Posts from Your Wordpress Feed

posted by jangro on (4 years, 2 months ago)

"rabbit rabbit". Happy March.

While it's not my primary blogging subject, I've got a major subculture here around the subject of DIY electronics repair. My Samsung DLP television is my usual guinea pig, and I get a decent amount of traffic on that topic.

Naturally, I want to write more about that and I have plans to do so, but annoying my regular readers, the people I know personally, with that stuff has always kept me in check.

I discovered this morning that I can write about that stuff and keep those posts out of my regular feed as well as keep them off the homepage if I wish.

It's quite simple to do so. Just add the following code to your template's functions.php file:

function myFilter($query) {
    if ($query->is_feed) {
        $query->set('cat','-5');
    }

return $query; }

addfilter('preget_posts','myFilter');

That will keep category with ID 5 out of the feed. You can get the IDs by looking in the wp_terms table in your database. With wordpress 2.1, these terms are tags and categories, and while I haven't tested it with tags, I have seen that it does work with Categories.

If you want to exclude more than one category, put them in separated by commas '-5,-10,-11'

This is a great solution if you've got some test posts or otherwise stuff you want to post but not hit the RSS. For example, if you're pulling all your twitter posts into your blog, you can avoid cluttering up your RSS with this info.

Also, if you want to keep posts off the homepage, you use if ($query->ishome) instead of isfeed. Or you can do both with this: if ($query->ishome || $query->isfeed)

Thanks to Zeo for this great info.


Comments & Reactions

  • Posted by Top 5 Ways to Exclude Posts from Your Wordpress RSS Feed - exclude categories, exclude posts, feedburner, Rss feed, stealth-publish, Ultimate Category Excluder, Wordpress - Technically Personal! 2013 years, 9 months ago

    [...] of isfeed. Or you can do both with this: if ($query->ishome || $query->is_feed). Thanks Jangro for this [...]

  • jangro saved this to Wordpress 4 years, 2 months ago
  • Posted by Vlad 4 years, 2 months ago

    This is good. I was looking for something like this for quiet some time. Thanks.

  • Posted by Vlad 4 years, 2 months ago

    What about the readers that would be interested just in those posts? Just relying on SE to index those pages?

  • scott

    Posted by Scott 4 years, 2 months ago

    Good question Vlad. I'm not sure, but I think you can get feeds on specific categories from wordpress. I'd have to research that a bit.

  • Posted by Vlad 4 years, 2 months ago

    Please update here if you find a solution. I am working on something similar.

  • Posted by brackets 4 years, 2 months ago

    Can't you set up seperate feeds for seperate categories? There may not be a plugin to do it easily, but it should be doable.

  • Posted by design hotels 4 years, 2 months ago

    for category feed you must use this : http://example.com/category/categoryname/feed' href='http://example.com/category/categoryname/feed">http://example.com/category/categoryname/feed'>http://example.com/category/categoryname/feed">http://example.com/category/categoryname/feed more information here : http://codex.wordpress.org/WordPressFeeds' href='http://codex.wordpress.org/WordPressFeeds">http://codex.wordpress.org/WordPressFeeds'>http://codex.wordpress.org/WordPressFeeds">http://codex.wordpress.org/WordPress_Feeds

  • Posted by Exclure certains articles de votre flux RSS 4 years, 2 months ago

    [...] Via Jangro [...]

  • Posted by sachinKT 4 years, 2 months ago

    thanks for the info !! i will try it ....

  • Posted by Vlad 4 years, 2 months ago

    @desing hotels-??? (cute name ;) )

    Your suggestion will only work if you decide exclude posts on the home page of the blog. The code that Scot is going to use is placed in functions.php - I am afraid that it will either give an error or 404 page for the path "/categoryname/feed"

  • Posted by design hotels 4 years, 2 months ago

    @Vlad glad you like my name ;) You've probably right about the 404 page... I'll try this on a test blog.

  • Posted by Vlad 4 years, 2 months ago

    @design hotels

    I am interested in this solution. Currently I have a category on one of my wordpress sites where I exclude certain category from the front page but not from the main feed. I did not have time to try if modifying functions.php will affect the "category feed"

  • Posted by Exclude a category from your Wordpress feed | ChillyCool Web Digger 4 years, 2 months ago

    [...] Excluding Posts from Your Wordpress Feed That will keep category with ID 5 out of the feed. You can get the IDs by looking in the wp_terms table in your database. With wordpress 2.1, these terms are tags and categories, and while I haven’t tested it with tags, I have seen that it does work with Categories. [...]

  • Posted by Jessica 4 years, 1 month ago

    I didn't want to exclude a whole category from my feed, so I made a tag to add to entries I didn't want in the feed instead. I changed "cat" in the code you gave to "tag" (and the ID, obviously), and it works perfectly - thank you for that!

  • Posted by Jessica 4 years, 1 month ago

    I didn't want to exclude a whole category from my feed, so I made a tag to add to entries I didn't want in the feed instead. I changed "cat" in the code you gave to "tag" (and the ID, obviously), and it works perfectly - thank you for that!

  • Posted by nonhocapito 4 years ago

    when I try this trick under WP 2.5 with feeds I get all the post in REVERSED order! I think it is because of the new RANDOM order introduced with 2.5. So far I was not able to come with any solution... to set query['order'] as well doesn't work.

  • Posted by bay of islands nz 4 years ago

    Nice trick, thanks for that, I'll be using that in my sites to lop off spurious content from the feeds...

  • Posted by bay of islands nz 4 years ago

    Nice trick, thanks for that, I'll be using that in my sites to lop off spurious content from the feeds...

  • Posted by Nico 3 years, 7 months ago

    Has anyone seemed to figure out how to fix the problems of reversed order when using this function? It seems that when I include this in functions.php all my posts are shown in reverse chronological order.

  • Posted by How to: exclude categories from your rss feed 3 years, 7 months ago

    [...] goes to Scott Jangro for this awesome [...]

  • Posted by Planeta WordPress » Blog Archive » WordPress: cómo excluir una categoría del feed RSS 3 years, 6 months ago

    [...] En la RMD, uno de los problemas que había inicialmente es que los miniposts de los feeds agregados en tu blog, también se incluyen en tu feed. Y eso puede suponer una inconveniencia para los suscriptores que no desean nada más que leerte a tí. Hay muchas formas de resolver el inconveniente pero, quizás, una de las mejores es la que veíamos en el blog de Scott Jangro: Excluding Posts from Your Wordpress Feed. [...]

  • Posted by Most Wanted WordPress Hacks: 11 New Requests (2) | Link Archive 3 years, 5 months ago

    [...] This code will execlude categories ID=”79″ and ID=”26″ from your feed. Thanks to Jangro’s tip [...]

  • Posted by New semester and how to hide posts in Wordpress : In-House Translators - A Dying Breed 3 years, 4 months ago

    [...] like that and I think it may be of interest for other people too. I got the instructions from Jangro 2.0. I had a hard time finding the category ID but it is explained on the Wordpress Support [...]

  • Posted by Speed Reader X 3 years, 4 months ago

    Thanks for this. It is what I'm looking for!

  • Posted by Customize WordPress Theme-Exclude Category | One Stop Themes 3 years, 4 months ago

    [...] To avoid that problem. We must filter the posts before the loop begin. Finally i find the right way here. [...]

  • Posted by 10????WordPress RSS?? | ??????? 3 years, 3 months ago

    [...] Excluding posts from your WordPress feed [...]

  • Posted by Wordpress: Como excluir uma categoria do FEED | S u s p e n s a . info | 4.0 3 years, 2 months ago

    [...] Encontrei essa dica fantástica aqui [...]

  • Posted by KRUZ-GRAPHIX | RSS??????????????????Wordpress??? 3 years, 2 months ago

    [...] ?????jangro?Excluding Posts from Your Wordpress Feed? ?? php function, ????????, ??? [...]

  • Posted by Wordpress?10????RSS?????(?) | WordPress???? 3 years, 2 months ago

    [...] ???Excluding posts from your WordPress feed Tags: ??, RSS, WordPress, ?? [...]

  • Posted by BS 3 years, 1 month ago

    That works to remove undesired categories from the main feed, but it prevents you from generating individual feeds for individual categories.

    For example, our main site feed is at:


    http://www.mysite.com/index.php/feed

    We also had individual category feeds available on each category page using somthing like the following:


    http://www.mysite.com/?cat=8&feed=rss2

    Those individual category feeds now all display the main site feed. I'm guessing that's because the code you provided sets the categories to display. Is there any way to alter the code so that it only applies to the main site feed?

  • Posted by 10???WordPress RSS Feed???(2) - ???? 3 years, 1 month ago

    [...] Excluding posts from your WordPress feed [...]

  • Posted by ??? » Blog Archive » wordpress??????RSS?? 3 years, 1 month ago

    [...] Excluding posts from your WordPress feed [...]

  • Posted by Exclude WordPress Categories from Your RSS Feed 2 years, 11 months ago

    [...] goes to Scott Jangro for this awesome [...]

  • Posted by Exclude WordPress Categories from Your RSS Feed | CodeTricky 2 years, 11 months ago

    [...] goes to Scott Jangro for this awesome script! Share this [...]

  • Posted by Most Wanted WordPress Hacks: 11 New Requests (2) | Webmaster Zone - Cyooh.com 2 years, 9 months ago

    [...] This code will execlude categories ID=”79″ and ID=”26″ from your feed. Thanks to Jangro’s tip [...]

  • Posted by 10????WordPress RSS?? | ???? 2 years, 9 months ago

    [...] Excluding posts from your WordPress feed [...]

  • Posted by WPExplorer 2 years, 5 months ago

    Nice tutorial, thank you.

  • Posted by WPExplorer 2 years, 5 months ago

    Nice tutorial, thank you.

  • Posted by How-To Build A Searchable Lifestream » Daniel C Berman Communications 2 years, 4 months ago

    [...] XXX with the category number from your lifestream category. A big thank you to Jangro.com for this [...]

  • Posted by 10???WordPress RSS Feed???(2) « ??? 2 years, 3 months ago

    [...] Excluding posts from your WordPress feed [...]

  • Posted by 20+ WordPress Codes You Might Need On Your Next Project | Web Design Philippines | MikeWagan.net 2 years ago

    [...] Via: WpRecipes Credits: Scott Jangro [...]

  • Posted by icenslice 2 years ago

    Sometimes I update a blog post and I don't want it to go through the feed again (and it does...using Feedburner).
    How can I filter for that?

    Thanks for the great WP tips!

  • Posted by Wordpress?10????RSS?????(?) | ???? 1 year, 11 months ago

    [...] ???Excluding posts from your WordPress feed [...]

  • Posted by Geek is a Lift-Style. » Blog Archive » 10 Useful RSS-Tricks and Hacks For WordPress 1 year, 11 months ago

    [...] Excluding posts from your WordPress feed [...]

  • penisibuyutme shared this on  6 months, 2 weeks ago
  • macizle

    Posted by macizle 4 months, 1 week ago

    canl? maç izle maç izle,lig tv izle


Leave a comment


Comment via Facebook

Listed Under

Reactions

Tags
    This item hasn't been tagged.