total noob with Timber and Twig. Im using Advanced Custom Fields with Timber and Twig. In the custom fields I have a field that allows the user to check 3 of any category through a taxonomy field type with the return value of term object.
What I am trying to do is show 3 of any category the user selected and 3 of the associated posts from that category underneath. I have like 14 categories overall.
Would look like this
In my PHP file I have
$context['categories'] = Timber::get_terms('category');
In my Twig file:
````
{% for featured_topic in post.get_field('featured_topics') %}
<div class="col-md-4 featured-topics-widget">
<h4>{{featured_topic.name}}</h4>
<ul>
{% for topic in topic_post %}
<li>{{topic.title}}</li>
{% endfor %}
</ul>
</div>
{% endfor %}
The code above spits out the category title which is fine but Im stuck figuring out how to show the posts that belong to it. any help would be appreciated!!!
Edit: I wrote this query (I dont know what Im doing ). It pulls the posts but just duplicates. Sorry putting the question on gitgub. :)
PHP
$topic_args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => array( 81, 92, 82, 1, 88, 86, 85)
)
)
);
$context['topic_post'] = Timber::get_posts($topic_args);
TWIG
{% for featured_topic in post.get_field('featured_topics') %}
<div class="col-md-4 featured-topics-widget">
<h4>{{featured_topic.name}}</h4>
<ul>
{% for cat in topic_post.posts('category') %}
<li><a href="{{ cat.link }}">{{cat.name}}</a></li>
{% endfor %}
</ul>
</div>
{% endfor %}