The taxonomy field works similar to the Post object field, but targeted on terms, allowing you to choose one or more taxonomy terms. By default, it displays title of the chosen items.

Displaying detailed information about terms (Pro)

In the Pro version, you can make a separate View to display target term fields, and choose that View in the settings of the current field to display the detailed information. See the Relationship field example for the guide.

Displaying items hierarchically (Pro)

By default, all the items displayed in the same order, in which were selected in the field. If your taxonomy supports hierarchy, and you want to reflect it on the front, you can group the items by the parent_id field.

See the Twig template example below.

<acf-view-65ae6721b4917 class="{{ _view.classes }}acf-view acf-view--id--{{ }} acf-view--object-id--{{ _view.object_id }}">

    {% if taxonomy.value %}
        <div class="acf-view__taxonomy">
            {% for term_item in taxonomy.value %}
                {% if 0 == term_item.parent_id %}
                    [acf_views view-id="{{ taxonomy.view_id }}" object-id="term" term-id="{{ term_item.value }}"]

                    {% set children = [] %}

                    {% for inner_term_item in taxonomy.value %}
                        {% if term_item.value == inner_term_item.parent_id %}
                            {% set children = children|merge([inner_term_item]) %}
                        {% endif %}
                    {% endfor %}

                    {% if children %}
                        <div class="children">
                            {% for child_term_item in children %}
                                [acf_views view-id="{{ taxonomy.view_id }}" object-id="term" term-id="{{ child_term_item.value }}"]
                            {% endfor %}
                    {% endif %}
                {% endif %}
            {% endfor %}
    {% endif %}


Note: the template above expects that you've filled the View setting to get the detailed item information, but you can use the same approach with utilizing the 'parent_id' field even when you display items just as links.

Last updated