I have custom post types called Product
. Under Products I have custom taxonomies called colour
and type
.
Colour has the terms - Red
, Yellow
, White
Type has the terms - Type 1
, Type 2
, Type 3
.
Product A is colour yellow and is of Type 1.
So I want to display this information.
Please help in how I can achieve this?
You can use get_the_terms(). This returns an "Array of term objects on success", so you will have to reference the element in the array, and then the appropriate property of the object. Assuming you want to get the first term name of each:
$colourArray = get_the_terms( $post_id, 'colour');
$colour = $colourArray[0]->name;
$typeArray = get_the_terms( $post_id, 'type');
$type = $typeArray[0]->name;