getTerm($slug, $termFields)
Get all the registered terms for a given taxonomy.
Usage
site()->getTerm($slug, $termFields);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$slug | string | Yes | The slug of a taxonomy |
$termFields | array | No | A string array of fields, see below for possible options. |
Possible Fields
term_id– Returns the term’s idid– Shortcut forterm_idname– The term’s nametitle– Same asnameslug– The term’s slugurl– Returns the result ofget_term_link($term)permalink– Same asurlterm_group– The term’s grouptaxonomy– The slug of the term’s taxonomy (Will always be the same as the$slugparameter)description– The term’s description, if setparent– The term’s parentcount– Cached object count for this term
Any member of WP_Term can be accessed this way.
Returns
| Type | Description |
|---|---|
array | If fields were provided, values will be returned under those keys. Otherwise an array of WP_Term objects will be returned. |
Example
Getting the name and slug for all the terms within the car_type taxonomy.
site()->getTerm('car_type', ['name','slug']); // Returns[ [ "name" => "Hatchback", "slug" => "hatchback" ], [ "name" => "Hyper Car", "slug" => "hypercar" ], [ "name" => "Sports Car", "slug" => "sportscar" ], ... // And more]