getPostTaxonomy($post, $key)
Get a post’s terms for a certain taxonomy.
Usage
site()->getPostTaxonomy($post, $key);
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
$post | WP_Post | Yes | The post to find the terms of |
$key | string | Yes | The key (aka slug) of the taxonomy to find the terms of |
Returns
Type | Description |
---|---|
WP_Term[] | false | An array of WP_Term objects on success, or false if there are no terms or the post does not exist. |
Example
Getting the terms of current post for the taxonomy 'car_type'
site()->getPostTaxonomy(get_post(), 'car_type'); // Returns[ object(WP_Term) [ "term_id" => 5, "name" => "Hatchback", "slug" => "hatchback", ... // Other WP_Term attributes ], object(WP_Term) [ "term_id" => 6, "name" => "Sports Car", "slug" => "sportscar", ... ], ...]