getPostTaxonomy($post, $key)

Get a post’s terms for a certain taxonomy.

Usage

site()->getPostTaxonomy($post, $key);

Parameters

ParameterTypeRequiredDescription
$postWP_PostYesThe post to find the terms of
$keystringYesThe key (aka slug) of the taxonomy to find the terms of

Returns

TypeDescription
WP_Term[] | falseAn 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",
        ...
    ],
    ...
]