Support » Fixing WordPress » How to hide categories in the feeds?

  • Resolved Xander


    I’d like to make it so that posts in one of my categories does not go out with the feed. The Category Visibility plugin used to do this, but it isn’t compatible with WP2.0.1. Does anyone know a simple way to accomplish this?

    What I’m currently trying is throwing the line $posts = get_posts(‘category=-6’); just before the loop begins in the rss/rss2 feed templates. Is this a bad idea? Does anyone have a recommendation of a better way to make this happen? Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Whoops, get_posts doesnt have the little -x trick to exclude one category, but query_posts works fine. The line from wp-rss2.php that did the trick:

    <?php $items_count = 0; query_posts(‘cat=-6’); if ($posts) { foreach ($posts as $post) { start_wp(); ?>

    The only addition is the query_posts(‘cat=-6’); piece… the feeds come out with all other categories, just the way I want it.

    Posted here in case it comes up in someone’s search for the same info…

    Of course nothing is as simple as it seems! That didn’t work as desired. Here’s what I ended up with (and I’m crossing my fingers I don’t find some new wrinkle)… sample from wp-rss2.php:

    <?php $items_count = 0; if (!is_category()) { query_posts(‘cat=-6’); } if (!in_category(‘6’)) { if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    <title><?php the_title_rss() ?></title>
    <?php if (get_settings(‘rss_use_excerpt’)) { ?>
    <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
    <?php } else { // use content ?>
    <description><![CDATA[<?php the_content_rss(”, 0, ”, get_settings(‘rss_excerpt_length’)) ?>]]></description>
    <?php } ?>
    <link><?php permalink_single_rss() ?></link>
    <?php rss_enclosure(); ?>
    <?php do_action(‘rss_item’); ?>
    <?php $items_count++; if (($items_count == get_settings(‘posts_per_rss’)) && empty($m)) { break; } } } } ?>

    Its that first line that is really important… IF the feed is not for a category, query_posts and get everything except cat 6 posts. If however one is in category 6, don’t display anything in the feed. This keeps category 6 out of action as far as I can tell, with the added bonus of not mucking with the other feeds as far as I know.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to hide categories in the feeds?’ is closed to new replies.