Timber: How to extend an array of WP post objects from ACF with Timber\Post

Created on 11 Jul 2018  路  2Comments  路  Source: timber/timber

This is a support question. I am using WordPress, Advanced Custom Fields, and Timber to build a theme. I am using an ACF relationship field to choose featured posts for one of my pages. This relationship field returns an array of WP post objects.

I grab this array and add it to my Timber $context with the following code:


/* featured posts */
$featured_posts = get_field('insights_featured_posts');
$context['featured_posts'] = $featured_posts;

I would like each of the WP post objects within this array to be extended using Timber/Post. I am not sure the best way to accomplish this with an array of post objects. Any help would be appreciated.

This is my twig file that accesses the $featured_posts array:

{% for post in featured_posts %}
 <div class="col ns-col-is-4">
 <h3 class="post-heading">{{post.post_title}}</h3>
 <p class="post-content">{{post.post_excerpt}}</p>
 </div>
{% endfor %}
question

All 2 comments

Wow. Could that be added to the Timber\Post convert() documentation? :)

Was this page helpful?
0 / 5 - 0 ratings