WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] WP 3.1 breaks RSS customization via exclude_category? (14 posts)

  1. mikeindustries
    Member
    Posted 3 years ago #

    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');

  2. MK Safi
    Member
    Posted 3 years ago #

    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...

  3. Mark Jaquith
    WordPress Lead Dev
    Posted 3 years ago #

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

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

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

    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');
  5. Michael Clark
    Member
    Posted 3 years ago #

    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.

  6. Reports are coming in that it does work! :)

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

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

  8. Michael Clark
    Member
    Posted 3 years ago #

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

  9. henri
    Member
    Posted 3 years ago #

    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

  10. lipak
    Member
    Posted 3 years ago #

    @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.

  11. henri
    Member
    Posted 3 years ago #

    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');
  12. lipak
    Member
    Posted 3 years ago #

    @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.

  13. rs11
    Member
    Posted 2 years ago #

    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');

  14. 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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags