Term

Single term entity

Properties & methods

PropertyType

ID

Term ID

int

ancestor

Retrieves the root ancestor of a term

object

ancestors(reverse)

Retrieves the ancestors of a term

array

children(args)

Get term children

array

content(nl2br)

Get term description

string

count

Related post count

int

depth

Hierarchical depth

int

excerpt

Get filtered term description

string

link

Term url

string

custom_fields(name)

Get ACF value

mixed

meta(name)

Get term meta

mixed

parameters

Get term url parameters based on rewrite rules

object

parent

Term parent

object

path

Relative term link without prefix

string

posts(post_type, order, limit)

Get related posts, return PostCollection

object

post_types

Get related post types

array

slug

Get term slug

string

taxonomy

Get taxonomy slug

string

template

Return "template" term meta

string

thumbnail

Get ACF "thumbnail" field if defined

object

title

Get term title

string

has_parent

Check if term has parent

bool

is_current

Check term id against queried_object_id

bool

is_public

Return true if taxonomy is viewable

bool

Examples

Display term meta

{{ term.meta.my_field }}

Display ACF fields

Display a repeater fields with position and title sub-fields https://www.advancedcustomfields.com/resources/get_field/

{% for item in term.custom_fields.items %}
    {{ item.position }} {{ item.title }}
{% endfor %} 

Display thumbnail

<a href="{{ term.link }}">
    <img src="{{ term.thumbnail(467,251) }}" alt="{{ term.thumbnail.alt }}"/>
</a>

or using picture twig filter

<a href="{{ term.link }}">
    {{ term.thumbnail|picture(467,251,{'min-width: 1025px':[399,215]}) }}
</a>

Query posts : $post_type='post', $orderBy=null, $limit=null, $offset=null

{% for post in term.posts('guide') %}
  <span class="post-link">
    <a href="{{ post.link }}">{{ post.title }}</a>
  </span>
 {% endfor %}t

Last updated