admin管理员组文章数量:1288023
I'm trying to find out whether the post has_term
by post ID or not.
Right now I have this:
<?php $postid = $_GET['post_id'];
if( has_term( 'campaign', 'type' ) ): ?>
//Do something
<?php endif; ?>
How do I incorporate $postid variable inside the has_term
?
So that I could check only that specific post id.
I have tried:
<?php $postid = $_GET['post_id'];
if( has_term($postid, 'campaign', 'type' ) ): ?>
The above doesn't work.
Need help, thanks.
I'm trying to find out whether the post has_term
by post ID or not.
Right now I have this:
<?php $postid = $_GET['post_id'];
if( has_term( 'campaign', 'type' ) ): ?>
//Do something
<?php endif; ?>
How do I incorporate $postid variable inside the has_term
?
So that I could check only that specific post id.
I have tried:
<?php $postid = $_GET['post_id'];
if( has_term($postid, 'campaign', 'type' ) ): ?>
The above doesn't work.
Need help, thanks.
Share Improve this question edited Sep 7, 2021 at 16:34 robert0 asked Sep 7, 2021 at 16:23 robert0robert0 2032 silver badges11 bronze badges1 Answer
Reset to default 1The 3rd parameter of has_term()
accepts a WP_Post or Post ID. Docs on has_term()
. In your example code, it would look like this:
<?php $postid = $_GET['post_id'];
if( has_term( 'campaign', 'type', $postid ) ): ?>
//Do something
<?php endif; ?>
Where campaign
would be the term, type
would be the taxonomy, and $postid
is the post that may have the campaign
term.
本文标签: phpIf post ID hasterm
版权声明:本文标题:php - If post ID has_term? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741335124a2372996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论