WordPress.org

Support

Support » Alpha/Beta » [Resolved] WP 3.1 breaks RSS customization via exclude_category?

[Resolved] WP 3.1 breaks RSS customization via exclude_category?

  • I’ve been using a standard exclude_category call in my functions.php file for years in order to exclude things like tweets from my main RSS feed. Since upgrading to WP 3.1, it appears this no longer works. Did something change with pre_get_posts or something? My code is below —

    function exclude_category($query) {
    	if ( $query->is_feed && $query->query_vars['all'] != 'true' ) {
    		$query->set('cat', '-473,-281');
    	}
    return $query;
    }
    
    add_filter('pre_get_posts', 'exclude_category');

Viewing 13 replies - 1 through 13 (of 13 total)
  • I have this problem, too. They are talking about it here: http://core.trac.wordpress.org/ticket/16545 but I don’t completely understand what they’re saying…

    Moderator Mark Jaquith

    @markjaquith

    Verified. Unintentional, and a bug. Moving it over to Trac.

    http://core.trac.wordpress.org/ticket/16622

    This should work instead:

    function exclude_category($query) {
    	if ( $query->is_feed && $query->query_vars['all'] != 'true' ) {
    		$query->set('category__not_in', array(473,281));
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    I updated my plugin at http://www.planetmike.com/plugins/ultimate-category-excluder/ . I really need to add it to the WordPress.org plugin list. Please test it and let me know if it works for you or not.

    Reports are coming in that it does work! 🙂

    Yeah, do repo-up if you can, so people get notified automagically 😀

    And yes, it’s now in the WordPress plugin directory: http://wordpress.org/extend/plugins/ultimate-category-excluder/

    HI all do you know how I can exclude some cats from the main feed and still have a feed for the category excluded?

    Assuming category 7 is named “test”

    use this :

    // Exclude category from feed
    function myFilter($query) {
    	if ($query->is_feed) {
    		$query->set('category__not_in',array(7));
    
    	}
    return $query;
    }
    add_filter('pre_get_posts','myFilter');

    And still have http://mydomain.com/category/test/feed ?

    Thanks all

    @henri, I think you are trying to do the same thing as I am.

    Adding Otto’s code above in \wp-content\themes\x\functions.php I excluded one category that I no longer wanted to output in my main RSS feed. This code seems to still allow you to directly access feeds for the category you have just excluded by using the following:
    http://www.mydomain.com/?feed=rss2&category_name=excluded_category_name
    category_name will be the same as the one used for links that allow you to view a Category.

    Initially I was trying to use the “Ultimate Category Excluder” plugin however it is so thorough that the excluded feed was no longer available by any means.

    Hope this helps.

    try this it’s work for me

    function myFilter($query) {
    	if ($query->is_feed && !is_category()) {
    		$query->set('category__not_in',array(29,39));
    
    	}
    	if ($query->is_home) {
    		$query->set('category__not_in',array(39));
    
    	}
    return $query;
    }
    add_filter('pre_get_posts','myFilter');

    @henri, that seems to have worked. Assuming I understand the code correctly, I only need the category excluded from the main RSS feed but I am fine with having it output on the main site/blog, so I did not include:

    if ($query->is_home) {
    		$query->set('category__not_in',array(39));
    
    	}

    I really appreciate your snippet since I realized shortly after my last post that what I suggested above only appeared to be working because of FeedBurner causing a delay in reflecting the change on my feed.

    Thanks.

    Hi, I’m new to WordPress and have been trying very hard to make the exclude code below work. I’ve attempted many different variations (including the “function my filter” approach above).

    The goal is to allow two categories of posts to appear only on a home page of a WordPress website while a third category appears only on a separate draft page of the website. (And, later, a fourth category of posts will appear on a separate “page two” of the website). The home page was designed to be presented through an empty, linked “index.php” page. And the home page and the draft pages have their own linked templates (page-home.php and page-draft.php).

    What’s happening is that one command is overriding the other command and forces the one command to apply to both situations, no matter how I reword or re-order the command. It’s often the home page command that overrides the other, but sometimes it’s the other way around. (I’ve also tried labeling the page-home as home, index, etc.)

    If you have run across this problem before, I’d really appreciate your advice.

    function exclude_category($query) {
    if ( $query->is_page-draft.php) {
    $query->set(‘category__not_in’, array(1));

    }
    if ( $query->is_page-home.php) {
    $query->set(‘category__not_in’, array(2,3));

    }
    return $query;
    }
    add_filter(‘pre_get_posts’, ‘exclude_category’);

    rs11 – This is for WP 3.1 ALPHA testing.

    Please repost this in a NEW topic, all your own, in http://wordpress.org/support/forum/how-to-and-troubleshooting

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] WP 3.1 breaks RSS customization via exclude_category?’ is closed to new replies.
Skip to toolbar