In a Magento 2.3.3 store I am trying to ouput the values of a multiselect custom attribute on a category page, but not having any luck.
I have set the attribute to be used in product listing and tried to output it on catalog/product/listing.phtml template page in my custom theme.
I am using the using the following code:
<?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('custom_attribute')->getFrontend()->getValue($_product); ?>
This is working for dropdown attributes but not multi select attributes.
Kind of stuck on this…
2
Answers
You can use the below code to get MultiSelect Attribute value
create block in “catalog_product_view.xml”
create “phtml” file under “Magento_Catalog::product/view/attribute_name.phtml”
Here is an example of a code that returns "Multiselect Attribute Values". The attribute belongs to product entity. As it isn’t a good idea to get ProductResource model from ProductModel and taking into account that probably you need to get it inside some template, just create a ViewModel and use this example there.