admin管理员组文章数量:1406060
I have to display a button that links to a tag, but I have to hide the button if tag doesn't exists to avoid broken links.
How can I check if a specific tag exists inside wp database?
This is what I have so far:
$tag_path = '/tag/testing/';
if( !$page = get_page_by_path( $tag_path ) ){
//hide button link
} else {
//show button link
}
I have to display a button that links to a tag, but I have to hide the button if tag doesn't exists to avoid broken links.
How can I check if a specific tag exists inside wp database?
This is what I have so far:
$tag_path = '/tag/testing/';
if( !$page = get_page_by_path( $tag_path ) ){
//hide button link
} else {
//show button link
}
Share
Improve this question
asked Apr 13, 2017 at 21:35
bpybpy
2995 silver badges20 bronze badges
2 Answers
Reset to default 5I think you're looking for term_exists
function.
Example Code:
<?php
$term = term_exists('tag1', 'post_tag');
if ($term !== 0 && $term !== null) {
echo "'tag1' post_tag exists!";
} else {
echo "'tag1' post_tag does not exist!";
}
?>
I think you can check has_tag
if(has_tag('tag_name')) {
// do something
} else {
// do something
}
Ref - https://developer.wordpress/reference/functions/has_tag/
本文标签: taxonomycheck if tag exists in wp database
版权声明:本文标题:taxonomy - check if tag exists in wp database 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744964424a2634856.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论