admin管理员组文章数量:1122846
I have a queried list of calendar events that I am trying to check if they have custom taxonomy terms. Within the loop, I have a list of "if" statements for outputting terms from the Accessibility Options taxonomy for each instance, like so:
if ( has_term('closed-captions', 'accessibility-options') ) { echo 'CC'; }
None of these work. However, when I do this:
$access_options = get_the_term_list( $post->ID, 'accessibility-options', '', ', ', ' ' );
echo $access_options
It outputs the expected terms. I have tested it by putting an exact post ID into the has_term statement and gotten the expected results. But it does work as is or when I use $post->ID in the parameters.
I tried outputting the post ID to check that, and when I do, I don't get the actual post ID. For example, if I am expecting the post ID to be 48445. I instead get 10000854.
Any insights are appreciated!
I have a queried list of calendar events that I am trying to check if they have custom taxonomy terms. Within the loop, I have a list of "if" statements for outputting terms from the Accessibility Options taxonomy for each instance, like so:
if ( has_term('closed-captions', 'accessibility-options') ) { echo 'CC'; }
None of these work. However, when I do this:
$access_options = get_the_term_list( $post->ID, 'accessibility-options', '', ', ', ' ' );
echo $access_options
It outputs the expected terms. I have tested it by putting an exact post ID into the has_term statement and gotten the expected results. But it does work as is or when I use $post->ID in the parameters.
I tried outputting the post ID to check that, and when I do, I don't get the actual post ID. For example, if I am expecting the post ID to be 48445. I instead get 10000854.
Any insights are appreciated!
Share Improve this question asked Oct 7, 2024 at 19:51 GrabBag-CharlesGrabBag-Charles 211 bronze badge 1 |1 Answer
Reset to default 0If your second code block is in the same code block as your first, then adding $post->ID
as the third parameter of the has_term()
call should fix it:
if ( has_term( 'closed-captions', 'accessibility-options', $post->ID ) ) { echo 'CC'; }
If it doesn't then as Tom mentioned, please update your question to include the surrounding relevant code.
本文标签: wp queryhasterm not returning anything
版权声明:本文标题:wp query - has_term not returning anything 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283971a1927144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_posts
without callingset_current_post(
then WordPress won't be able to guess which post you're referring to when you callhas_term
but I can't tell from your code as the surrounding post loop is missing. There's a high chance the problem is in code not shared! – Tom J Nowell ♦ Commented Oct 7, 2024 at 20:27