WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 8 months ago

#20092 closed enhancement (wontfix)

Add Exclude by Tag to Queries

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

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)

comment:2 solarissmoke2 years ago

  • Component changed from Feeds to Query
  • Summary changed from Add Exclude by Tag to Feed Queries to Add 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.

comment:3 iridox2 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...

comment:4 wonderboymusic8 months ago

  • Keywords close reporter-feedback added

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

comment:5 wonderboymusic8 months ago

  • Keywords close reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Use tag__not_in

Note: See TracTickets for help on using tickets.