• Resolved candregg

    (@candregg)


    I’m looking for function code to selectively exclude posts to the feeds based on tag. I found the code below in a post from a couple of years ago, but cannot make it work (php newbie). I need to exclude posts with tag ID 740, but leave all the other posts alone.

    Any help would be appreciated.

    C

    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');
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I believe simply inserting this line:
    $tag[] = 740;
    just above the $query-> set('tag__not_in', $tag); should do the trick.

    Thread Starter candregg

    (@candregg)

    That worked a treat, thanks very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Function to exclude posts from feed by tag’ is closed to new replies.