Reputation: 1
I have setup a custom post type with a custom taxonomy as categories.
I need to use get_the_terms
or wp_get_post_terms
to return the first category of a post in the custom post type.
But I can't quite figure out how to use it in comparison to get_the_category
.
Upvotes: 0
Views: 396
Reputation: 188
https://codex.wordpress.org/Function_Reference/wp_get_post_terms
This is a very useful resource, if you are within the loop already it will return an array of categories. To access the first one you could assign the array to a variable and call the first one.
$arr = wp_get_post_terms();
$first = $arr[0];
Or the last
$last = array_pop((array_slice($arr, -1)));
Upvotes: 1