viktorix
Member
Posted 1 year ago #
I've created a new feed template file and trying to get it to exclude several posts based on a tag they have. I'm including this code at the top of a php file that generates feed:
function exclude_tag_rss($query) {
if ( $query->is_feed) {
$query-> set('tag__not_in',array(206));
}
return $query;
}
add_filter('pre_get_posts','exclude_tag_rss');
Where am I wrong? It's not excluding posts with tag 206.
Thanks guys!
Evan Jacobs
Member
Posted 1 year ago #
Hey bud! In case you didn't figure it out, I recently got this to work with the following code snippet.
function exclude_tags_rss($query) {
if ( $query->is_feed) {
if( isset($_GET['tag__not_in']) ) {
$qv = $_GET['tag__not_in'];
if( strpos($qv, ',') !== false) $tag = explode(',', $qv);
else $tag[] = $qv;
}
$query-> set('tag__not_in', $tag);
}
return $query;
}
add_filter('pre_get_posts','exclude_tags_rss');
You then can filter out tags with the following syntax:
http://yourdomain.com/feed?tag__not_in=5,12,40
Enjoy!