Display a Vendor Attribute in the Listing Block

Could you please share with me a snippet to display a vendor attribute in the listing block?

I did some research and could get a value of a custom text attribute. But when I want to retrieve a value of an “select” type attribute , it returns NULL. (I need to retrieve the string selected, not the id):

	function ($blocks, $template){
		$listing = $template->get_context('listing');

			return $blocks;
		$vendor = $listing->get_vendor(); 
		$text_value = $vendor->get_one_text_attribute(); -----> OK
                $select_value = $vendor->get_one_select_attribute() ----> RETURNS NULL

Please try to change $vendor->get_one_select_attribute() on $vendor->get_one_select_attribute__id(). This way you can get term IDs of a custom selectable attribute

Hi, the problem is that I need the option value selected (for example a country name), instead of the ID.

In this case please use this code to get the option label:

$label = $vendor->display_attributenamehere();

Please note that if Multiple selection is enabled for it then there may be comma separated labels as a single string, not an array like with IDs.

it worked! Thank you!

1 Like