繁体   English   中英

类别页面上的 ACF 组

[英]ACF group on category page

我使用高级自定义字段 ( https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/ ) 为我的博客类别创建了字段组。

当我创建基本文本字段时,很容易在 category.php 上使用:

$terms = get_the_terms( get_the_ID(), 'category');

if( !empty($terms) ) {
    $term = array_pop($terms);
    $custom_field = get_field('some_text_field', $term );
}

echo $custom_field;

但是我创建了一个组(称为 call_to_action)而不是基本的文本字段,其中包含 4 个字段(图像、标题、副标题、链接)。 现在,如果我尝试创建不同的变量,例如:

$custom_field1 = get_field('image', $term );
$custom_field2 = get_field('title', $title );
$custom_field3 = get_field('subtitle', $title );
...

并回应他们,什么也没有发生。

我猜这是因为它们位于“call_to_action”组中......我真的不知道如何让它们出现......我只是从 PHP 开始,任何想法都会非常感谢

试试这个方法

$custom_field3 = get_field('subtitle');

或者

global $post;  
$custom_field3 = get_field('subtitle',$post->ID);

或者

$custom_field3 = get_field('subtitle',get_the_id());

暂无
暂无

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

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