admin管理员组文章数量:1332881
I'm trying to see if a post (thru id) has a specified tag
if has_tag( $tag = 'Cat', $post = $post_id ) {
$taganimal = "Cat";
}
I tried this, but it just crashes the site .
Got idea from /, but can't get it to work..
I'm trying to see if a post (thru id) has a specified tag
if has_tag( $tag = 'Cat', $post = $post_id ) {
$taganimal = "Cat";
}
I tried this, but it just crashes the site .
Got idea from https://developer.wordpress/reference/functions/has_tag/, but can't get it to work..
Share Improve this question asked Jun 28, 2020 at 20:18 JoBeJoBe 1712 silver badges11 bronze badges1 Answer
Reset to default 1You should wrap your condition with brackets according to PHP syntax:
if (has_tag('Cat', $post_id)) {
$taganimal = "Cat";
}
If you need to check multiple tags you can use something like
foreach (['Cat', 'Dog'] as $animal) if (has_tag($animal, $post_id)) {
$taganimal = $animal;
break;
}
but it would find only the first tag listed in array in case the post has several of them.
本文标签: searchSee if a post has a specified tag
版权声明:本文标题:search - See if a post has a specified tag 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742311392a2450943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论