【发布时间】:2020-02-04 11:36:42
【问题描述】:
我在 WordPress 中使用 Roots Sage 9 并使用 FrontPage.php 控制器,其中已经定义了 protected $acf = true; 工作正常,它在大多数情况下输出我期望的内容。
在首页的 ACF 配置中,我有一个关系字段 (portfolio_items),它从名为 portfolio 的自定义帖子类型中提取帖子,其中包含许多额外的 ACF 字段。
现在,我遇到的问题是我只能想象 ACF 的范围之类的问题。对于在首页 ACF 字段中定义的内容,整个 protected $acf 工作正常,但在我的 foreach 中,我试图访问自定义帖子类型中定义的 ACF 字段,但我无法让它们输出信息。例如,我定义了一个名为“存档标题”的文本字段,我通常会使用the_field('archive_title') 输出它,但是当我尝试使用控制器时,我尝试将其用作$archive_title,但没有运气,我只需获取 “注意:未定义变量:archive_title”
这是我目前正在使用的完整代码:
<?php global $post ?>
@foreach($portfolio_items as $post)
@php(setup_postdata($post))
@php($thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "xlarge" ))
@php($thumbnail_image = $thumbnail[0])
<a href="{{ the_permalink() }}" class="col-md-3 direction-reveal__card">
<img src="{{ $thumbnail_image }}" alt="Image" class="direction-reveal__img">
<div class="direction-reveal__overlay direction-reveal__anim--enter">
<h3 class="direction-reveal__title mt-auto">{{ $archive_title }}</h3>
</div>
</a>
@endforeach
<?php wp_reset_postdata(); ?>
我想不出一种完全正确访问其他字段的方法。有没有人遇到过这种情况?
【问题讨论】:
标签: wordpress advanced-custom-fields acfpro roots-sage