【问题标题】:To get meta field (ACF) in taxonomy template在分类模板中获取元字段 (ACF)
【发布时间】:2017-08-18 05:52:18
【问题描述】:

我在一个分类页面中,在一个自定义分类和特定术语 URL 中:

http://localhost:3000/personas/cristina-aiken-soux/

另外,我有这个页面的分类模板:

taxonomy-personas.php

在此模板中,我正在尝试恢复并显示一个高级自定义字段:

$term_object = get_queried_object();
the_field('picture', $term_object->term_id);

但没有返回任何内容。为什么?

如果我这样做print_r($term_object); 我可以看到查询的对象:

WP_Term Object ( 
    [term_id] => 2 [name] => Cristina Aiken Soux 
    [slug] => cristina-aiken-soux 
    [term_group] => 0 
    [term_taxonomy_id] => 2 
    [taxonomy] => personas 
    [description] => Cras in elementum enim, vitae volutpat sapien. Duis at sem in quam ultrices hendrerit. Class aptent taciti sociosqu ad litora torquent. 
    [parent] => 0 
    [count] => 2 
    [filter] => raw 
)

那么,为什么我无法恢复 de ACF?

谢谢!

【问题讨论】:

  • 我在您的 $term_object 中没有看到“图片”?
  • 你试过ACF的get_field函数吗??
  • 这可能会有所帮助:advancedcustomfields.com/resources/…
  • 是的,我都试过了,get_field 和 the_field。谢谢!
  • 图片不在term_objet中,为此我使用$term_object->term_id来获取自定义字段:the_field('picture', $term_object->term_id);

标签: php wordpress advanced-custom-fields custom-taxonomy


【解决方案1】:

终于找到了解决办法

$foto = get_field('fotopersona', 'personas'.'_'.$term_object->term_id);

【讨论】:

    猜你喜欢
    • 2022-10-13
    • 2020-05-11
    • 2015-10-15
    • 2021-08-28
    • 2015-10-12
    • 2020-07-21
    • 2015-09-05
    • 2019-05-07
    • 2019-05-22
    相关资源
    最近更新 更多