简体   繁体   English

在分类模板中获取元字段(ACF)

[英]To get meta field (ACF) in taxonomy template

I am in a taxonomy page, in a custom taxonomy and specific term URL: 我在分类页面中,在自定义分类和特定术语的URL中:

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

Also, I have a taxonomy template for this page: 另外,我对此页面有一个分类模板:

taxonomy-personas.php

Inside this template, I am trying to recover and show an Advanced Custom Field: 在此模板中,我试图恢复并显示“高级自定义字段”:

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

But nothig is returned. 但是nothig返回了。 Why? 为什么?

If i do print_r($term_object); 如果我做print_r($term_object); I can see the queried 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 
)

So, why can not I recover de ACF? 那么,为什么我不能恢复de ACF?

Thanks! 谢谢!

最后,我找到了解决方案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM