admin管理员组

文章数量:1431426

I have this function

$tags = get_tags( array('exclude' => 11, 12) )

Which excludes specific tags 11 and 12. But without manually having to add each tag ID I don't want shown, how do I exclude the category that these tags are coming from?

I have this function

$tags = get_tags( array('exclude' => 11, 12) )

Which excludes specific tags 11 and 12. But without manually having to add each tag ID I don't want shown, how do I exclude the category that these tags are coming from?

Share Improve this question edited May 1, 2019 at 17:44 harshclimate asked May 1, 2019 at 17:38 harshclimateharshclimate 217 bronze badges 5
  • Sorry, I really don't get it. Could you maybe rephrase your problem somehow? – norman.lol Commented May 1, 2019 at 17:47
  • note that asking the database to exclude the tag for you is going to be very expensive/slow. It's much easier, and significantly faster, to ask for all the tags then do an if statement to skip over those 2 tags – Tom J Nowell Commented May 1, 2019 at 17:53
  • Sorry, I'm having a hard time wording this question: Rather than specifying and manually adding tag id's to exclude from a category, is there a way to just add a category so that all tags from that category aren't shown? I hope that makes more sense... – harshclimate Commented May 1, 2019 at 18:08
  • You need a way to mark tags in admin, which will be automatically hidded on front-end, right? – anton Commented May 1, 2019 at 18:20
  • Tags don't belong to categories. They're just attached to posts. So no, here isn't a way to provide a category to exclude because tags and categories aren't related ike that. If you have multiple sets of tags that you use differently for posts in different categories, then you'd be better off created a separate taxonomy. – Jacob Peattie Commented May 2, 2019 at 9:28
Add a comment  | 

2 Answers 2

Reset to default -1

Since this question is too hard to ask, I'm going to use custom taxonomies. Thanks for your help so far, everyone.

You could get all of the term IDs for the badcategory and use those in your exclude filter:

$bad_terms = get_terms( [ 'taxonomy' => 'badcategory', 'fields' => 'ids' ] );
$good_tags = get_tags( [ 'exclude' => $bad_terms ] );

本文标签: tagsHow do I exclude categories from gettags