Make WordPress Core

Opened 15 years ago

Closed 13 years ago

#20092 closed enhancement (wontfix)

Add Exclude by Tag to Queries

Reported by: iridox Owned by:
Priority: normal Milestone:
Component: Query Version:
Severity: normal Keywords:
Cc: Focuses:

Description

Per scribu's instruction:

Category exclusion is already possible for feeds using a query string, tags should be the same.

Example:

http://domain.com?cat=news&tag=-featured&feed=rss2

Would equate to a feed of posts in the "news" category, not tagged "featured" and outputted via the RSS2 template.

Change History (5)

#2 @solarissmoke
15 years ago

  • Component FeedsQuery
  • Summary Add Exclude by Tag to Feed QueriesAdd Exclude by Tag to Queries

I think this would require introducing a new query var that accepts tags by ID (in the same way that cat accepts category IDs). If that is going to happen, then it seems to me that if possible it should be done to work with any taxonomy and not just tags.

#3 @iridox
15 years ago

That would make sense. The way I've been achieving this filter so far is hooking into the pre_get_posts filter like so:

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

There must be a better way to do this...

#4 @wonderboymusic
13 years ago

  • Keywords close reporter-feedback added

Not sure what is requested here... tag__not_in seems like the way to go... maybe close this?

#5 @wonderboymusic
13 years ago

  • Keywords close reporter-feedback removed
  • Milestone Awaiting Review
  • Resolutionwontfix
  • Status newclosed

Use tag__not_in

Note: See TracTickets for help on using tickets.