在 wordpress 中获取当前帖子的分类术语

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13767120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:06:05  来源:igfitidea点击:

Getting a taxonomy term for the current post in wordpress

wordpress

提问by Ledgemonkey

I'm trying to populate a form value field with a taxonomy term associated with the current post,

我正在尝试使用与当前帖子关联的分类术语填充表单值字段,

I must have tried 20 things but cant find the right solution .?

我一定已经尝试了 20 件事,但找不到正确的解决方案。?

I have meta fields but that's easy I have just used this:

我有元字段,但这很简单,我刚刚使用了这个:

$ref = get_post_meta( $post->ID, 'job_ref', true ); 

and this for the form field:

这对于表单字段:

  <input type="text" class="text" name="job_ref" id="job_ref" value="
  <?php echo $ref; ?>" /> 

So I'm looking for a similar solution for a taxonomy term ..?

所以我正在为分类术语寻找类似的解决方案......?

Many thanks

非常感谢

回答by barakadam

Use wp_get_post_termsto retrieve your post terms. syntax here:

使用wp_get_post_terms检索您的文章条款。语法在这里:

http://codex.wordpress.org/Function_Reference/wp_get_post_terms

http://codex.wordpress.org/Function_Reference/wp_get_post_terms

回答by j08691

You can use get_the_terms(). The difference between get_the_terms()and wp_get_post_terms()is that get_the_terms()'s results are cached.

您可以使用get_the_terms(). get_the_terms()和之间的区别在于wp_get_post_terms()get_the_terms()的结果被缓存。