admin管理员组文章数量:1022997
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 |2 Answers
Reset to default -1Since 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 ] );
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
2 Answers
Reset to default -1Since 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
版权声明:本文标题:tags - How do I exclude categories from get_tags? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745534494a2154898.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
if
statement to skip over those 2 tags – Tom J Nowell ♦ Commented May 1, 2019 at 17:53