I'm using a Wordpress theme that was developed using Twig template system. I don't know anything about Twig an don't have the time to learn it.
So my question is, 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 has hierarchy.
I understand that I must have somewhere the place where wp.get_terms is defined but I can't find it.
Twig works more or less like plain PHP. For a function call you add parameters like you would in PHP:
{{ method(parameter1, parameter2) }}
Arrays can be defines using [
and ]
. Also associative arrays can be defined using {
and }
like this:
{% set array = [1, 2, 3] %}
{% set assoc = {'key': 'value', 'key2': 2} %}
So your function call should look something like this:
{% for distrito in wp.get_terms('Distritos', ['a', 'b', 'c']) %}
Checkout the twig docs for further information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With