Taxonomy term
For loop type taxonomy_term
, here are the query parameters and fields.
Query parameters
children
- Set true to include only child terms
Type: booleanexclude
- Exclude terms by ID(s) or slug(s)
Type: string, arrayhide_empty
- Hide terms not assigned to any post - true or false (default)
Type: booleanid
- Get terms by ID(s)
Type: number, arrayinclude
- Include terms by ID(s) or slug(s)
Type: string, arrayname
- Get terms by name/slug(s)
Type: string, arrayorder
- Order: asc (ascending) or desc (descending)
Type: string - Default: ascorderby
- Order by one of: name, title (default), term_id, menu_order, count
Type: string - Default: titleorderby_field
- Order by custom field
Type: stringorderby_field_number
- Order by custom field whose value is a number
Type: stringparent
- Get terms by its parent term's ID or slug
Type: number, stringparents
- Set true to include only top-level parent terms
Type: booleanpost
- Corresponding post ID(s) for term retrieval or "current" for current post
Type: number, arraytaxonomy
- Get terms by taxonomy
Type: stringterms
- Alias for "include"
Type: string, array
Fields
ancestors
- Ancestor term IDs (or loop instance) from lowest to highest level; Set reverse=true to go from top-level down
Loop type: taxonomy_termchildren
- Children term IDs (or loop instance)
Loop type: taxonomy_termcount
- Post countid
- Term IDname
- Term nameparent
- Parent term ID (or loop instance)
Loop type: taxonomy_termposts
- Loop instance of posts that belong to current term
Loop type: posttaxonomy
- Taxonomy name (or loop instance)
Loop type: taxonomytitle
- Term titleurl
- URL to term archive page
Shortcuts
Use the taxonomy
attribute as a shortcut.
<Loop taxonomy=category>
<Field title />
</Loop>
The above is the same as:
<Loop type=taxonomy_term taxonomy=category>
<Field title />
</Loop>
The Taxonomy
tag provides another way to express it.
<Taxonomy category>
<Term title />
</Taxonomy>
Examples
- How to order terms alphabetically by ACF text field and hide empty terms
- How to conditionally display something when the current post has a certain taxonomy term applied
- How to create loops within loops within loops
- How to display WooCommerce attributes
- How to add up the count of a parent taxonomy term with the count of all its children
- How to display term fields on a taxonomy term archive