Twig+WordPress how to use array arguments inside a function?

I already asked this on stack overflow but then I found this place.

I’ve searched but didn’t find any answer to this.

I’m using a theme that was developed using the Twig template system. I don’t know anything about Twig and I don’t have the time to learn it.

In wordpress we can use get_terms() to get all the terms from a taxonomy but we can “filter” the terms we want to receive using an array of arguments that is the second parameter to the function.

That being said, I have a line in a twig file that goes like this:

{% for distrito in wp.get_terms('Distritos') %} 

distrito is my variable and Distritos is my taxonomy name. This works, it calls all of the terms, but I want to use the array arguments so that I can get only the root elements since my taxonomy is hierarchical.

I understand that I must have somewhere the place where wp.get_terms is defined but I can’t find it and I’ve been around this for 2 days now.

Answer

If it is straight pass through to native WP function this might work:

{% for distrito in wp.get_terms('Distritos', {'foo': 'bar'} ) %}

However overall this is specific to implementation and is hard to guess without taking that code apart.

Attribution
Source : Link , Question Author : user2805223 , Answer Author : Rarst

Leave a Comment