0

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?

5
  • Sorry, I really don't get it. Could you maybe rephrase your problem somehow?
    – leymannx
    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... 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. Commented May 2, 2019 at 9:28

2 Answers 2

-1

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

-1

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 ] );
1
  • You've misunderstood the question. This code won't do anything. Tags can't belong to another taxonomy, so excluding specific categories from get_tags() doesn't make any sense. They're already not going to be included. Commented May 2, 2019 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.