检查 WordPress 数据库中是否存在标签

知更鸟 WordPress1 197阅读模式

我们有时可能会用到检查 WordPress 数据库中是否存在某个标签,例如一个按钮需要链接某个标签,当标签不存在时,则不显示按钮。

$term = term_exists( 'tag1' );
if ( $term !== 0 && $term !== null ) {
	echo '存在';
} else {
	echo '不存在';
}

检查是否存在标签tag1.文章源自知更鸟-https://zmingcx.com/check-if-tag-exists-in-wp-database.html 文章源自知更鸟-https://zmingcx.com/check-if-tag-exists-in-wp-database.html

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
评论  1  访客  1
    • 禹步网
      禹步网 2

      这个有用,优化不错

    匿名

    发表评论

    匿名网友 填写信息

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    确定