Damir Pećnik
Damir Pećnik

Reputation: 21

tax_query not working in Twig file in Timber

I am trying to get posts from the specific term in twig file but it appears that tax_query is not working with timber I get all posts from the post_type. Anyone knows what the issue is?

{% set query_parameters = {
     'post_type': 'myposttype',
     'tax_query': {
           'taxonomy': 'portals',
           'field': 'term_id',
           'terms': '89'
          }
}%}

{% set ones = wordpress.call('Timber::get_posts', query_parameters) %}

Upvotes: 1

Views: 813

Answers (1)

Damir Pećnik
Damir Pećnik

Reputation: 21

Found out that issue is here I was missing [] as the tax_query is an array!

{% set query_parameters = {
 'post_type': 'myposttype',
 'tax_query': [{
       'taxonomy': 'portals',
       'field': 'term_id',
       'terms': '89'
      }]

}%}

{% set ones = wordpress.call('Timber::get_posts', query_parameters) %}

Upvotes: 1

Related Questions