WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] RSS Feed - Exclude Some Categories (9 posts)

  1. JeffW
    Member
    Posted 9 years ago #

    I have a couple of categories of posts that I want to exclude from my RSS feed.

    How can I do this without hacking the code?

    I can't see how to do this via a plugin, as I don't know how to set a filter that only applies when RSS loops through the posts, but is not active when WP is diplaying posts on the site.

    Anybody got a quick solution for me? Point me in the right direction, and I will be able to finish off the plugin - provided there is a suitable RSS-specific hook that I can't see at the moment.

    Thanks
    Jeff

  2. ifelse
    Member
    Posted 9 years ago #

    To exclude one category i.e. category 3, add the following to the root index.php before the include to wp-blog-header.php:
    if(isset($_GET['feed'])) {
    $cat=-3;
    }

    To exclude multiple categories i.e. 3,4 and 5, you'll have to work backwards and include only the categories that you want i.e.
    if(isset($_GET['feed'])) {
    $cat='1 2 6';
    }

  3. ifelse
    Member
    Posted 9 years ago #

    Apologies, just read your post a bit more carefully and realised that you want to do this via plugin hooks and without hacking the code.

    I'll leave my above post up for reference but someone else will have to chime in to answer your specific request.

  4. Kafkaesqui

    Posted 9 years ago #

    Download this plugin:

    http://www.redalt.com/External/plugins.php?p=front-page-cats

    First you have to edit the $cats_to_show varariable in the plugin file to list the categories to display. Next, look for this bit (you'll find it in two places):

    $wp_query->is_home

    Change it to

    $wp_query->is_feed

    Upload the plugin file; activate it; the end. Oh, you may want to rename the plugin, so you don't get confused by it a few months from now (look for the Plugin Name: line -- perhaps you can call it "Feed Categories").

  5. JeffW
    Member
    Posted 8 years ago #

    Thanks for the prompt feedback.

    Sorry that I am only posting a response now - I found the front-page-cats code useful - learnt something new about tweaking WP / enabled me to achieve what I wanted.

    Jeff

  6. ckozus
    Member
    Posted 8 years ago #

    JeffW, I want to do the same thing. Is it possible for you to share the code to do that ?

    TIA,

    ckozus.

  7. LK
    Member
    Posted 8 years ago #

    This is a great workaround for excluding or including certain categories in a feed.

    Unfortunately, our site's need to employ the permalink structure category/postname breaks the feed. There is a long error message with the header "[Not unique table/alias: 'wp_post2cat']". The feed can be restored by deactivating the plugin, or changing the permalink structure to anything else.

    The burden of the category/postname permalink!

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Get the Category Visibility plugin. It can hide categories in lots of different ways, one of which is to remove them from the feed.
    http://www.gudlyf.com/archives/2005/03/08/wordpress-plugin-category-visibility/

  9. LK
    Member
    Posted 8 years ago #

    Txs for the tip. That plugin (updated here) works great for our particular setup. Much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags