function eliminate_tag_from_feed() {
global $query_string;
if (is_feed()) {
$vars=parse_str($query_string);
$vars['tag__not_in']=array(123,456,789);
query_posts($vars);
}
}
add_action('init','eliminate_tag_from_feed');
I think that will work. The numbers 123 and 456 and so on are the ID numbers of the tags to exclude.
Thanks so much, I will try it out and let you know how it works. 🙂
Incidentally, do you think this would be any more straightforward using a category rather than a tag?
Well, yes in that there exist plugins to do it for you for categories. 🙂
But, really, no. The code would be much the same. Slight differences only.
Doesn’t seem to be working:
function hide_noaff_posts_from_feed($post) {
global $query_string;
if(is_feed()) {
$vars = parse_str($query_string);
$vars['tag__not_in'] = array(29); // 29 is the id of the 'noaff' tag in the terms table
query_posts($vars);
}
}
[…]
add_action('init','hide_noaff_posts_from_feed');
The add_action() is wrapped in an if block that only executes if a certain GET param is set. I’ve verified that the code inside the if block is executing, but the test post tagged with noaff is still appearing in the feed.
Okay, based on my investigation, I found that is_feed() was not yet true at init. This post confirms:
http://comox.textdrive.com/pipermail/wp-hackers/2008-January/017441.html
However, the suggestion of using template_redirect in that post causes the feed URL to display rendered HTML content. I’m reading and not sure what hook to try.
loop_start works. Thanks all! Hope this thread can help someone.
I’ve actually noticed a problem — I am using the id of the ‘noaff’ tag in the wp_terms table, but that’s yielding incorrect results. It’s removing many posts that are not tagged with ‘noaff’. Perhaps I’m using the id from the wrong table?
Looked it up in the manage tags section and the id is correct, but it’s removing many posts from the feed that are NOT tagged with the particular tag. I’d appreciate any help, I’ve been trying to look at the WordPress code itself but I’m not getting anywhere.
I’m using a filter on pre_get_posts and it works for me.
So:
function filter_feed_posts($query) {
if($query->is_feed) {
//remove the tags
}
}
add_filter('pre_get_posts','filter_feed_posts');
Sorry, full function here:
function filter_feed_posts($query) {
if($query->is_feed) {
//array of tags to exclude, by tag number
$exclude_tags = array(1,2,3);
$query->set('tag__not_in',$exclude_tags);
}
add_filter('pre_get_posts','filter_feed_posts');
This problem was actually caused by a bug in MySQL. Upgrading our servers to the latest version fixed it.