查看帖子是否有指定的标签 时间:2020-06-28 作者:JoBe 我正在尝试查看帖子(thru id)是否有指定的标记 if has_tag( $tag = \'Cat\', $post = $post_id ) { $taganimal = "Cat"; } 我尝试了这个,但它只是使网站崩溃。从中获得想法https://developer.wordpress.org/reference/functions/has_tag/, 但无法使其工作。。 1 个回复 最合适的回答,由SO网友:Ivan Shatsky 整理而成 您应该根据PHP语法用括号将条件括起来:if (has_tag(\'Cat\', $post_id)) { $taganimal = "Cat"; } 如果需要检查多个标记,可以使用foreach ([\'Cat\', \'Dog\'] as $animal) if (has_tag($animal, $post_id)) { $taganimal = $animal; break; } 但如果帖子中有几个标签,它只能找到数组中列出的第一个标签。 文章导航