1
votes

Here's my setup:

Twig Version: 1.34.4    
ACF Pro 5.8.8

I have the following ACF fields created, and I am trying to translate a working web page from standard PHP over to Twig.

ACF Field Group > Group > Repeater > Post Object

At the repeater level, I can access other standard fields fine, and I'm displaying these without a problem on the Twig template. My problem is how I access inside the Post Object so I can pull out the standard WP fields Title, Content etc.

I'm referencing the ACF cookbook at https://timber.github.io/docs/guides/acf-cookbook/, and thought the Relationship field might work, as such:

{% for item in Post(post.relationship_field) %} 
   {{ item.title }}
   {# Do something with item #}
{% endfor %}

However this doesn't output anything at all so I'm not sure it's working.

In my PHP page, I'm only passing in the standard post context like so:

$context['post'] = $post;

Do I have to add anything else to the PHP page in order to make this work, or should I be able to do this natively in the Twig template?

1
Can you {{ dump(post) }} and see anything?Chris Haas
When I run a full dump on the post it shows the Post ID that I need to access. That's obviously not the Post Object. The ACF settings are correct (set to return the Post Object), and on the previous non-twig PHP webpage I had to run a separate WP_Query to get the object. What options do I have in Twig now then?pixelkicks

1 Answers

1
votes

Fixed! I came across this answer which solved it for me Issue with Post Object Timber/Twig WordPress. Though the Post ID was being returned in the dump, it seems I was trying to access it in an incorrect way.