Opened 13 years ago
Closed 12 years ago
#20092 closed enhancement (wontfix)
Add Exclude by Tag to Queries
Reported by: |
|
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)
#2
@
13 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.
#3
@
13 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...
http://domain.com?category_name=news&tag=-featured&feed=rss2
Fixed the example URL, woops.