【问题标题】:Getting a taxonomy term for the current post in wordpress在 wordpress 中获取当前帖子的分类术语
【发布时间】:2012-11-25 20:52:00
【问题描述】:

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

我一定尝试了 20 种方法,但找不到正确的解决方案。?

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

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

这是表单域:

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

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

非常感谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    使用wp_get_post_terms 检索您的帖子条款。这里的语法:

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

    【讨论】:

    • 非常感谢您的帮助...您已确认我将要使用的解决方案...
    • 你能给我们一个实现这个单CPT.php内部循环的例子吗?
    • 链接页面上有例子
    • 链接失效了。很高兴在这个答案中看到示例:-)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 2012-08-30
      • 2012-04-01
      相关资源
      最近更新 更多