简体   繁体   English

使用Timber从关系字段获取ACF

[英]Get ACF from relationship field with Timber

I'm using Advanced Custom Fields on a custom post type. 我在自定义帖子类型上使用“高级自定义字段”。 On the homepage I have a relationship field to select one of the posts in the custom post type. 在主页上,我有一个关系字段,可以选择自定义帖子类型的帖子之一。

Using Timber, I'm struggling to get the ACF fields for that relationship post into the Context. 使用Timber,我正在努力使该关系的ACF字段发布到Context中。 I can get the standard wordpress info like title and content, but not the ACFs. 我可以获得标准的wordpress信息,例如标题和内容,但没有ACF。

I think I need to use TimberPost, but haven't had any success so far. 我想我需要使用TimberPost,但是到目前为止还没有成功。

This is in my page template. 这是在我的页面模板中。 In the view it just outputs all the standard WP stuff: 在视图中,它仅输出所有标准WP内容:

$context['featureRelationship'] = get_field('feature');

So I tried this, but I'm going wrong somewhere: 所以我尝试了这个,但是我在某个地方出错了:

$context['featureRelationship'] = new TimberPost(get_field('feature'));

Appreciate any help, thanks 感谢任何帮助,谢谢

Sorted, so the php was right: 排序,所以PHP是正确的:

$context['featureRelationship'] = new TimberPost(get_field('feature'));

But I should have used a post object acf field instead of relationship 但是我应该使用post对象acf字段而不是关系

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

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